Latest web development tutorials

jQuery css () method

jQuery css () method

css () method sets or returns one or more style attributes of the selected element.


Returns CSS property

To return the value of the specified CSS property, use the following syntax:

css("propertyname");

The following example will return the first matching element of the background-color value:

Examples

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

try it"


Set CSS properties

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

css("propertyname","value");

The following example will match all the elements set background-color value:

Examples

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

try it"


Set multiple CSS properties

To set multiple CSS attributes, use the following syntax:

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

The following example will match all the elements set background-color and font-size:

Examples

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

try it"