etkronberg
etkronberg

Reputation: 37

JQuery: changing font-size not working

I am following a tutorial at thenewboston.com: I have copied exactly as the tutorial has given: his works but not mine: where is the error? The alert(current) should return the current font size: nothing works despite I have followed the tutorial precisely semicolon for semicolon and comma for comma. (I have repeatedly typed and retyped this according to the tutorial: it works in the tutorial but not for me. )

Here is the html:

  <!-- font size switcher-->
  Font size: <a href="#" id="smaller">Smaller</a>  <a href="#" id="bigger">Bigger</a>

 <p>This is some text</p>
  <p>This is some more text</p>

  <!--- script links --->  
  <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
  <script type="text/javascript" src="js/selectors_two.js"></script> 

Here is the code:

function change_size(element, size) {
    var currrent = element.css('font-size');
    // Check: alert() to return current font-size
    alert(current);

}
// derisive comment...
alert('Ha! You thought this would work!');

$('#smaller').click(function() {
change_size($('p'), 'smaller');
});

$('#bigger').click(function() {
change_size($('p'), 'bigger');
});

Even there is more coding following on at this stage of code all that is needed to happen is the alert(current). And it doesn't. Why?

And yes, I know about the use of .on(): I even tried to recast using .on().

Upvotes: 0

Views: 461

Answers (2)

Akshay Chawla
Akshay Chawla

Reputation: 613

Replace your code with below code

function change_size(element, size)
{
var current=element.css("font-size");
alert(current);
}

Upvotes: 0

LostMyGlasses
LostMyGlasses

Reputation: 3144

You have a typo: declared current with three 'r': var currrent.

Upvotes: 2

Related Questions