toggleClass() in jQuery
toggleClass() Method
The toggleClass() method toggles between adding/removing classes. So, if the class is present, then it will remove it otherwise if the class is absent then it will add it to the element.
Syntax:-
Its syntax is:- $(selector).toggleClass(classname, function(index, currentclass), switch)
Further Explanation:-
Parameter | Description |
---|---|
classname | Required. Specifies one or more class names to add or remove. |
function(index,currentclass) | Optional. Specifies a function that returns one or more class names to add/remove
|
switch | Optional. A Boolean value specifying if the class should only be added (true), or only be removed (false) |