jQuery toggleClass Method

jQuery toggleClass Method : is used to toggle class(es) to the selected elements. It Adds the class if it is not there on selected element and if it is there, it removes the class.

Syntax jQuery toggleClass Method

Here is syntax to create toggle class functionality-

index: (Interger) Index of the current element in the current set.
toggleClassName(String)Current Class name in the matching set.

jQuery toggleClass() Method Example 1

Try it »

The above code will produce following result-

Note : This is screenshot of the output. To run this demo click on the above “Try it” button.

Syntax jQuery toggleClass Method

📖 Read More