Virtual Classes Logo          Virtual Classes
    Read Anytime,Anywhere

Working with CSS

css() method sets or returns one or more style properties of the selected elements.

jQuery has several methods for CSS manipulation.
1-addClass() - Adds one or more classes to the selected elements
Example: $("div").addClass(" blue ");
Above code will add blue class to div element.

2-removeClass() - Removes one or more classes from the selected elements
Example : $(“div").removeClass(" blue ");
Above code will remove blue class from div element

3-toggleClass() - Toggles between adding/removing classes from the selected elements
Example: $(“div").toggleClass("blue");
Above code will add blue class to div element if blue class is not added already or remove if blue class is already added to div element.



4-css() - Sets or returns the style attribute of the selected element.
Syntex-css("propertyname","value");

Ex-$("p").css("background-color", "red");
will change the background color of p to red

$("p").css({"background-color": "red", "font-size": "200%"});
will change the background color of p to red and increate the font size of p .

$("p").css("background-color");
will return the background color of p which is previously set to red

The following css class is used for all the examples on this page:.blue { color: blue;}