Hanna
Hanna

Reputation: 10771

Changing CSS attribute with JQuery

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.

Upvotes: 2

Views: 6130

Answers (4)

Spaceghost
Spaceghost

Reputation: 6995

How about:

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

Upvotes: 1

PeeHaa
PeeHaa

Reputation: 72709

$('body').css('font-size', '5em'); 

Should work.

Upvotes: 5

Dogbert
Dogbert

Reputation: 222388

jQuery('body').css({fontSize:'5em'});

Upvotes: 7

Quentin
Quentin

Reputation: 944294

Quote key names and values in JavaScript object literals, and separate them with commas, don't terminate them with semi-colons.

{
    "font-size": "5em"
}

Upvotes: 2

Related Questions