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.
.css(property,value);
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:
$('p').css('color', '#F00');
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.
.css({prop:value,prop:vlaue,...});
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:
$('p').css({lineHeight:'18px',letterSpacing:'0.1em'});
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:
$('p').css({'line-height':'18px','letter-spacing':'0.1em'});
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.