Hi I want to change the font size of the page incrementally with jQuery how do I do that?
Something like:
$('body').css({'font-size':'+.01px'});
$('body').css({'font-size':'-.01px'});
To change the font size of an element, we will use css() method. The css() method is used to change the style property of the selected element. Return value: It will return the value of the property for the selected element.
In the javascript function, here changeFontStyle(), the fontFamily property value is set to the font value of the option selected. By default, it is set to Times New Roman. Output: Before selecting any option (Initial value – Times New Roman):
Start with the font you want, and always end with a generic family, to let the browser pick a similar font in the generic family, if no other fonts are available. Note: Separate each value with a comma. Note: If a font name contains white-space, it must be quoted.
You could do so :
var fontSize = parseInt($("body").css("font-size"));
fontSize = fontSize + 1 + "px";
$("body").css({'font-size':fontSize});
jsFiddle example here
You can't do it like that because the font propery is stored as a string, if you are sure the font size will be in pixels you could do it like this:
var fontSize = $('body').css('font-size').split('px')[0];
var fontInt = parseInt(fontSize) + 1;
fontSize = fontInt + 'px';
That might need modifying slightly I just wrote it without testing.
It might depend on which version of jquery, but I have used the following
HTML
<input type="button" id="button" />
<div id="box"></div>
CODE
$(document).ready(function() {
$("#button").click(function() {
$("#box").css("width","+=5");
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With