jQuery Tutorial
jQuery css() Method With Syntax and Example
What is css method in jQuery?
One or more style properties are set or returned by the CSS()
function. The value of the provided CSS attribute of the FIRST matched element is returned by this function when used to return properties.
Shorthand CSS properties (like "background"
and "border"
), on the other hand, are not fully supported and may produce different results across browsers.
Syntax of css method in jQuery
-
Return the value of the CSS property:
$(selector).css(property)
-
Set the CSS property and value:
$(selector).css(property,value)
-
Set CSS property and value using a function:
$(selector).css(property,function(index,currentvalue))
-
Set multiple properties and values:
$(selector).css({property:value, property:value, ...})
Example of jQuery css method
The colour property of all p> elements should be set to:
$("button").click(function(){
$("p").css("color", "red");
});