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.

4 Answers 4

7
jQuery('body').css({fontSize:'5em'});
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.

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"
}

Comments

1

How about:

<script  type="text/javascript">
$("body").css("font-size","70%");
</script>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.