The toggleClass method in jQuery provides a mechanism for adding or removing a class or list of classes by name from selected elements.
The toggleClass method in jQuery provides a mechanism for adding or removing a class or list of classes by name from selected elements.
For example, if a CSS class has been applied to a div
and the user wishes to remove this class from the div
, the following code would accomplish this task:
theDiv.toggleClass('theClassName');
Documentation for the toggleClass method can be found in .toggleClass().