English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
jQuery css()The method retrieves or sets one or more style properties of the selected element.
This method provides a quick way to apply styles (inline styles) directly to HTML elements.
To return the value of a specified CSS property, use the following syntax:
$(selector).css(property)
The following example returns the background color of the clicked DIV:
$("div").click(function(){ $("this").css("background"-color"); });Test See‹/›
To set a specified CSS property and value, use the following syntax:
$(selector).css(property, value)
The following example sets the color attribute of all paragraphs:
$("button").click(function(){ $("p").css("color", "blue"); });Test See‹/›
When usingcss()MethodGetWhen setting property values, it will returnThe First Selected Elementvalue.
Usingcss()MethodSetWhen setting property values, it will beAll Selected ElementsSetting One or More Properties/Value pairs.
To set multiple CSS properties and values, use the following syntax:
$("selector").css({property:value, property:value, ...})
The following example sets multiple CSS properties and values for all paragraphs:
$("button").click(function(){ $("p").css({ "color": "white", "font"-size": ""1.3em", "background"-"color": "#"4285f4", "padding": ""20px" }); });Test See‹/›
For a complete reference of CSS methods, please visit ourjQuery HTML / CSS Reference.