jQuery - css() Method


jQuery css() Method

The css() function can change or show the style of certain parts on a webpage.


Return a CSS Property

To get the value of a particular CSS property, use this format:

css("propertyname");

This example will give you the background color of the FIRST matching element:


Set a CSS Property

To apply a particular CSS style, use this format:

css("propertyname","value");

Here's an example that changes the background color for all elements that match the specified criteria:


Set Multiple CSS Properties

To apply various CSS styles, use this format:

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

The next example will define a background color and text size for EVERY element that matches.