Getting and Setting CSS Properties
jQuery makes it extremely easy to get and set CSS values using the .css(property, [value])
method. For example, the following code retrieves the cursor
CSS property value of an element:
$("#buttonA").css("cursor");
Then the following sets the border-radius
value:
$("#buttonA").css("border-radius", "10px 15px");
The .css()
method also allows you to pass a map object with properties and values. This allows you to set several settings at once. For example, the following code uses .css()
to set the margin
, padding
, float
, and font-weight
attributes at the same time:
$("span").css({margin:0, padding:2, float:"left", ...
Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.