jQuery toggleClass()

The method toggleClass() alternates between adding and removing the specified classes to 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.

The following code create a toggle effect in your webpage. This method takes one or more class names as its parameter.

The above code would remove a class with one click and in second click it would again add the same class. As with the other methods, multiple class names can be provided, separated by a space.

run this source code Try it Yourself

This is a paragraph

This is a Div

Full Source
 (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About