Tutorialsplane

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-

$(selector).toggleClass(classname,function(index,currentClassName));

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

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.

Jquery Tutorial

jQuery Effects

jQuery Traversing

jQuery HTML

jQuery Css

jQuery Scroll

jQuery Dimensions

jQuery Ajax