May 07, 2021 jQuery
1. jQuery - Gets and sets the CSS class
5. jQuery removeClass() method
jQuery makes it easy to manipulate CSS elements.
jQuery has several methods for performing CSS operations. We'll learn the following:
addClass() - Add one or more classes to the selected element
removeClass() - Remove one or more classes from the selected element
ToggleClass() - Switch to add/remove classes for selected elements
css() - Set or return style properties
The following style sheets will be used for all examples on this page:
The following example shows how to add class properties to different elements. Of course, when you add a class, you can also select multiple elements:
You can also specify multiple classes in the addClass() method:
Tip: Want to know about the specific exercise of jQuery using the addClass() method to add class to an element? Please refer to this site's jQuery programming practice!
The following example shows how to remove the specified class property from different elements:
Tip: From the example above, have you learned how to remove class properties in jQuery? Perhaps you can also consolidate your knowledge by programming the "Class with jQuery to remove HTML elements" section of the jQuery programming battle on this site!
The following example shows how to use the jQuery toggleClass() method. This method switches the selected elements to add/remove classes:
We'll cover the jQuery css() approach in the next chapter.
If you need the full contents of the jQuery CSS method, please visit our jQuery Reference Manual - CSS Operations!