Get all of the classes on an element as a string, add a class or classes, or completely replace or remove all classes.
CSS
Add, remove, toggle, and check for the presence of a class
Here are some handy, simple ways to manipulate CSS classes.
Find all matching elements on a page with document.querySelectorAll()
Find all matching elements on a page. You can use any valid CSS selector.
Apply a CSS animation to an element with JavaScript
A helper function to apply a CSS animation to an element with JavaScript.
Select an element or list of elements
Select an element or elements by given ID, class name, tag name, or CSS selector.
Check If an Element is Visible in the Viewport
In this tutorial, you’ll learn how to check if an element is visible in the viewport using JavaScript.
Replace a Class of an Element
To replace a class of an element with a new one, you use the replace() method of the classList property of the element.
Check If an Element contains a Class
To check if an element contains a class, you use the contains() method of the classList property of the element.
Toggle a Class of an Element
To toggle a class of an element, you use the toggle() method of the classList property of the element.
Remove a Class from an Element
To remove a class from an element, you use the remove() method of the classList property of the element.