jquery onclick toggle class next
snippet in javascript

jquery onclick toggle class next

user1694


$("button").click(function(){
  $("p").toggleClass("main");
 });
 

jquery toggle class

user7959

Definition and Usage
The toggleClass() method toggles between adding and removing one or more class names from the selected elements.

This method checks each element for the specified class names. The class names are added if missing, and removed if already set - This creates a toggle effect.

However, by using the "switch" parameter, you can specify to only remove, or only add a class name.

Syntax
$(selector).toggleClass(classname,function(index,currentclass),switch)

Example
Toggle between adding and removing the "main" class name for all <p> elements:
$("button").click(function(){
  $("p").toggleClass("main");
 });