Let’s see the different functions belonging to classList API:
classList property of HTML elements is the heart of classList API. It exposes all the classList API functions.
add() function is used to add a new class to the HTML element.
remove() is used to remove a class.
Sometimes we need to add or remove a class name based on a user interaction or the state of the site. This is done using the toggle() method
The classList API provides a method for retrieving class names based on it’s position in the list of classes.
length property returns the total number of classes attached to the element.
contains() is used to check if a class exists in a element or not.
It returns class list as a string.
Old Browser Support
Very old browsers don’t support classList API therefore use the classList Polyfill.