O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required