2

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

7
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

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.
5
$('body').css('font-size', '5em'); 

Should work.

answered Jan 21, 2011 at 20:40

Comments

2

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

1

How about:

<script type="text/javascript">
$("body").css("font-size","70%");
</script>
answered Jan 21, 2011 at 20:40

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.