jQuery

jQuery Intro

jQuery Intro Quiz

jQuery Intro Exercise

jQuery Basic

jQuery Basic Quiz

jQuery Basic Exercise

jQuery Advance

jQuery Advance Quiz

jQuery Advance Exercise

jQuery Selectors

jQuery Effects

jQuery Events

jQuery Methods and Properties

jQuery Traversing

jQuery CSS and HTML Methods

jQuery toggleClass() Method

jQuery toggleClass() Method

 

 

The toggleClass() method is used to toggle between adding and removing one or more class names from the selected elements. It 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.

 

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
  • index - Returns the index position of the element in the set
  • currentclass - Returns the current class name of selected elements
switch Optional. A Boolean value specifying if the class should only be added (true), or only be removed (false)

Code Explanation

All Tutorials related to jQuery CSS and HTML Methods

All Sections related to jQuery