O'Reilly logo

jQuery Essentials by Troy Miles

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

Classes and styles

The first method in the classes and styles group is .css(). This method is very powerful and shows why jQuery is a required and useful library even in the age of HTML5 browsers. The .css() method operates as both a getter and a setter. As a getter, it returns the computed style property or properties. It takes as arguments either a single string that is the name of a CSS property you would like to retrieve or an array of strings representing all of the CSS properties:

// .css(), retrieving a single property var backgroundColor = $(".jumbotron > .container > p > a").css("background-color"); console.log("Background Color = " + JSON.stringify(backgroundColor)); // .css(), retrieving multiple properties in a single call var colors ...

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