Today I was shown a really simple way to change the font-size
of an element using jQuery.
It looked very similar to the following:
<script type="text/javascript">
jQuery(document.body) ({font-size:5em;});
</script>
This obviously doesn't work, but I was wondering what's missing? I remember it being just one line of code.
Note: I have tried jQuery(document.body).css({font-size:5em;});
as well, without success.
Thanks.
Josh Darnell
11.5k9 gold badges40 silver badges66 bronze badges
asked Jan 21, 2011 at 20:37
4 Answers 4
jQuery('body').css({fontSize:'5em'});
answered Jan 21, 2011 at 20:39
Sign up to request clarification or add additional context in comments.
1 Comment
Hanna
Yeah, this code works! I've actually tried this in the past and it didn't work, my problem was that I kept it in the head tags instead of putting it at the bottom.
$('body').css('font-size', '5em');
Should work.
answered Jan 21, 2011 at 20:40
Comments
Quote key names and values in JavaScript object literals, and separate them with commas, don't terminate them with semi-colons.
{
"font-size": "5em"
}
answered Jan 21, 2011 at 20:39
Comments
How about:
<script type="text/javascript">
$("body").css("font-size","70%");
</script>
answered Jan 21, 2011 at 20:40
Comments
lang-js