jQuery - css() Method


jQuery css() Method

The css() method sets or returns one or more style element to selected elements.


Return a CSS Property

To restore the value of a specified CSS feature, use the following syntax:


css("propertyname");

The following example will return the color background of the matching element FIRST:


Example
$("p").css("background-color");


Set a CSS Property

To set the specified CSS feature, use the following syntax:


css("propertyname","value");

The following example will set the background color for ALL the same features:


Example
$("p").css("background-color", "yellow");


Set Multiple CSS Properties

To set multiple CSS features, use the following syntax:


css({"propertyname":"value","propertyname":"value",...});

The following example will set the background color and font size for ALL the same features:


Example
$("p").css({"background-color": "yellow", "font-size": "200%"});