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

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
  • 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 Basic

All Sections related to Jquery