Reference: jQuery css method
Gets or sets one or more styles for the selected elements.
Get a style
Parameters
- name of the style property
Returns
Value of the style property
Syntax
$(selector).css("propertyName")
Example
Get the background color of the first div.
var color = $("div").css("background-color");
Set a style
Parameters
- name of the style property
- value of the style property
Syntax
$(selector).css("propertyName", "value");
Example
Set the background color of the div elements to blue.
$("div").css("background-color", "blue");
Set multiple styles
Parameters
- JSON Object containing the property style and value pairs to set.
Syntax
$(selector).css({ "propertyName": "value", "propertyName": "value", ... });
Example
Set the height and width to 100px, and background color of the div elements to blue.
$("div").css({ height: "100px", width: "100px", "background-color": "blue" });