jQuery css()Method
Examples
Set the color property of all <p> elements:
Try it yourself »
Definition and Usage
The css() method sets or returns one or more style properties for the selected elements.
When used to return properties:
This method returns the specified CSS property value of the first matched element.
However, shorthand CSS properties (such as "background" and "border") are not fully supported and, when used to return property values, have different results in different browsers.
When used to set properties:
This method sets the specified CSS property for all matched elements.
Syntax
Return the CSS property value:
Set CSS property and value:
Set CSS property and value using a function:
Set multiple properties and values:
| Parameters | Description |
|---|---|
| property | Specifies the CSS property name, such as "color", "font-weight", etc. |
| value | Specifies the value of the CSS property, such as "red", "bold", etc. |
| function(index,currentvalue) | Specifies a function that returns the new value of the CSS property.
|
More Examples
Return the CSS property value
Returns the specified CSS property value of the first matched element.
Set CSS property and value using a function
How to use a function to change CSS properties for selected elements.
Set multiple CSS property-value pairs
How to set multiple CSS properties and values for selected elements.
Other Extensions
jQuery
HTML/CSS Methods