The JQuery .css() method provides a function to set CSS properties and values for any element. The .css() method will also retrieve the value of any CSS poperty for any element.
To set a CSS property use of the of the following methods.
Using this system set the property as the first parameter and the value as the second. Both parameters should strings. Use the standard CSS property names, the same as used in your CSS style sheet. For example:
The line above would find all p tags on a page and set the color to red.
Sometimes you may want to set multiple properties at once. In these cases use this syntax.
In this case pass one parameter, an object containing all of the properties and values to be set. Since property names set in the object can not contain special characters you’ll need to alternate property names. For example normally you would use background-color in your CSS style sheet. When using an object property list the – (hyphen) is not allowed. Instead use: backgroundColor. Notice I removed the unacceptable character and began the next word with an uppercase letter. For example:
The example above sets the line height and letter spacing of all p elements.
Alternately, the CSS property name can be used as long as it is wrapped in quotes. For example the line above could alternatively be written as:
The value of any property may also be retrieved. For example, imagine you wanted the font-size of one element to match the font-size of another.
$('li').css('font-size', $('#headline').css('font-size') );
The line above sets the font size of all li elements to the same font-size as that of the element with the id name #headline.