Classlist.toggle Javascript Code Example
Example 1: toggle css class in javascript /* var or const followed by its name */ . getElementById ( /* HTML element ID */ ) ; /* var or const's name */ . classList . toggle ( /* Name of CSS class */ ) ; // I hope this helps! Example 2: classname toggle js document . getElementById ( 'myButton' ) . onclick = function ( ) { this . classList . toggle ( 'active' ) ; } Example 3: js classlist classList . item ( index ) ; // Returns the item in the list by its index, or undefined if index is greater than or equal to the list's length classList . contains ( token ) ; // Returns true if the list contains the given token, otherwise false. classList . add ( token1 [ , ... tokenN ] ) ; // Adds the specified token(s) to the list. classList . remove ( token1 [ , ... tokenN ] ) ; // Removes the specified token(s) from the list. classList . replace ( oldToken , newToken ) ; // Replaces token with newToken. classList . supports ( token ) ; // R...