css() method in jQuery
css() Method
The css() method can be used to get and set CSS property values. its syntax is:-
$("div").css("property-name","property-value");
To set multiple CSS properties, the css() method uses JSON syntax.Its syntax is:-
css({"property":"value","property":"value",...});
Syntax:-
- Syntax for returning value of CSS property is:- $(selector).css(property)
- Syntax for setting value of CSS property is:- $(selector).css(property,value)
- Syntax for settings multiple properties and values is:- $(selector).css({property:value, property:value, ...})
- Sntax for setting property and value with function is:- $(selector).css(property,function(index,currentvalue))
Further Explanation:-
Parameter | Description |
---|---|
property | Specifies the CSS property name. |
value | Specifies the value of the CSS property. |
function(index,currentvalue) | Specifies a function that returns the new value for the CSS property
|