JQuery Font Size Script Problem
I'm working on a simple script to increase/decrease font-size using Jquery. Here's the HTML:
<head>
<title>Font Sizer</title>
</head>
<body>
<a id="increase" href="#">+</a><br/>
<a id="decrease" href="#">-</a>
<p>blah blah blah blah blah blah blah blah blah</p>
</body>
The JQuery Code:
$(document).ready(function(){
var textsize = $('p').css("font-size");
var textunit = textsize.slice(-2);
textsize = parseFloat(textsize, 10);
console.log(textsize);
$('#increase').click(function(){
textsize++;
console.log(textsize);
('p').css('font-size开发者_StackOverflow', textsize + textunit);
});
});
I'm working on jsFiddle, so no script tag for Jquery needed.
Could someone tell me why the font size doesn't increase when I click the +?
You are forgetting the "$" sign before ('p')
, it should be:
$('p').css('font-size', textsize + textunit);
精彩评论