简体   繁体   中英

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().

您有一个错字:用三个'r'声明为currentvar currrent

Replace your code with below code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM