jQuery’s css() method is used to set or read the css attributes of HTML elements.
The CSS syntax for reading elements is as follows:
css("propertyname");
For example, the following code gets the background color of the first
element.
[javascript]
$("p").css("background-color");
$("p").css("background-color");
Use the following Syntax to set CSS properties of HTML elements:
css("propertyname", "value");
For example, the following code sets the background color to yellow for all
elements.
[html]JQuery Demo This is a heading
This is a paragraph.
This is a paragraph.
This is a paragraph.
This is a paragraph.
JQuery Demo This is a heading
This is a paragraph.
This is a paragraph.
This is a paragraph.
This is a paragraph.
www.2cto.com
css() also supports multiple CSS properties at the same time: its syntax is as follows:
css({"propertyname":"value","propertyname":"value",…});
For example:
[javascript] view plaincopyprint?
$("p").css({"background-color":"yellow","font-size":"200%"});
$(" p").css({"background-color":"yellow","font-size":"200%"});