Friday, 22 July 2011

Setting multiple CSS attributes at a time using jQuery

This can be done by passing a comma seperated list of "attributeName:value" pairs to the .css() jQuery method.

Syntax

.css({ attributeName-1:"value",attributeName-2:"value",...attributeName-N:"value" })

For example to the following line sets the font-family and font-size of all paragraphs in the page.

$("p").css({fontFamily:"verdana", fontSize:"25px", color:"green"});

This can also be aschieved by the following script.


$("p").css("fontFamily","verdana");
$("p").css("font-size",25);
$("p").css("color","green");

No comments:

Post a Comment