jQuery Tutorials
jQuery Effects
jQuery HTML
jQuery Traversing
jQuery AJAX
jQuery Misc
With jQuery, it's easy to trick the style of the elements.
jQuery has several methods for CSS manipulation. We will look at the following methods:
addClass()
- Adds one or more classes to the selected elements
removeClass()
- Removes one or more classes from the selected elementstoggleClass()
- Toggles between adding/removing classes from the selected elementscss()
- Sets or returns the style attributeThe following style sheet will be used for all the examples on this page:
The following example shows how to add class attributes to different elements. Yes you can select multiple elements, when adding classes:
You can also specify multiple classes within the addClass()
method:
The following example illustrates how to remove a class attribute from different elements:
The following example will show how to use the jQuery toggleClass()
method. This method changes between adding / removing classes from selected items:
The jQuery css()
method will be explained in the next chapter.