Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

jQuery css() method


May 07, 2021 jQuery


Table of contents


jQuery - css() method


jQuery css() Method

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


Returns the CSS property

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

css(" propertyname ");

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

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

Try it out . . .


Set the CSS property

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

css(" propertyname "," value ");

The following example sets the background-color value for all matching elements:

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

Try it out . . .


Set more than one CSS property

To set more than one CSS property, use the following syntax:

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

The following example sets background-color and font-size for all matching elements:

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

Try it out . . .

Related articles

If you need the full contents of the jQuery CSS method, please visit our jQuery Reference Manual - CSS Operations!