![]() |
VOOZH | about |
In this article, we will see how to toggle between two classes in jQuery. To make the classes toggle, we will use toggleClass() method. The toggleClass() method is used to toggle or switch the class with the selected class element.
Syntax:
$(selector).toggleClass(class1 class2)
Example 1: In this example, we will create a button with a class and then use togggleClass() method to toggle (add/remove) another class to change the button styles on the button toggle.
Output:
Example 2: In this example, we will create a div element with a class and then use togggleClass() method to toggle (change) the div element styles on the button toggle.
Output: