Advanced JavaScript Training
Class List 

Class List

The classList property provides methods for working with CSS classes on elements. You can add, remove,toggle, or check the presence of classes.

  
    // Add a class to an element
    element.classList.add('active'); 
     // Remove a class from an element 
    element.classList.remove('inactive'); 
    // Toggle a class on an element 
    element.classList.toggle('highlight'); 
    //Check if an element has a class
    if (element.classList.contains('visible')) {
   // Do something
   } 
  
  
Have a doubt?
Post it here, our mentors will help you out.