Is there any syntactical way in jQuery to define multiple CSS attributes without stringing everything out to the right like this:
$("#message").css("width", "550px").css("height", "300px").css("font-size", "8pt");
If you have, say, 20 of these your code will become hard to read, any solutions?
From jQuery API, for example, jQuery understands and returns the correct value for both
.css({ "background-color": "#ffe", "border-left": "5px solid #ccc" })
and
.css({backgroundColor: "#ffe", borderLeft: "5px solid #ccc" }).
Notice that with the DOM notation, quotation marks around the property names are optional, but with CSS notation they're required due to the hyphen in the name.
pass it a json object:
http://docs.jquery.com/CSS/css#properties
You Can Try This
Best Way to use variable
please try this,
Try this
Using a plain object, you can pair up strings that represent property names with their corresponding values. Changing the background color, and making text bolder, for instance would look like this:
Alternatively, you can use the JavaScript property names too:
More information can be found in jQuery's documentation.