The css() method sets or returns one or more inline style properties for the selected elements.
While adding and removing classes is cleaner, sometimes you need to dynamically calculate exact pixel values or colors.
To return the value of a specified CSS property, use this syntax: css("propertyname");
This will read the computed style directly from the first matched element.
$("button").click(function(){
alert("Background color = " + $("p").css("background-color"));
});
To set a specified CSS property, you pass both the property name and the new value.
Syntax: css("propertyname", "value");
This will apply the style to ALL matched elements on the page.
$("button").click(function(){
$("p").css("background-color", "yellow");
});
To set multiple CSS properties at the exact same time, you pass a JSON object.
Syntax: css({"propertyname":"value", "propertyname":"value", ...});
$("button").click(function(){
$("p").css({
"background-color": "yellow",
"font-size": "200%"
});
});
If you call the css() method with only one parameter (the property name), what does it do?
What format must you use to pass multiple CSS properties into the css() method at once?