VOOZH about

URL: https://www.geeksforgeeks.org/jquery/how-to-toggle-between-two-classes-in-jquery/

⇱ How to Toggle Between Two Classes in jQuery ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Toggle Between Two Classes in jQuery ?

Last Updated : 23 Jul, 2025

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:

👁 Image
 

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:

👁 Image
 
Comment
Article Tags:

Explore