element.classList
is of DOMTokenList
type.
Is there a method to clear this list?
To remove all classes from an element, set the element's className property to an empty string, e.g. box. className = '' . Setting the element's className property to an empty string empties the element's class list.
The Element. classList is a read-only property that returns a live DOMTokenList collection of the class attributes of the element. This can then be used to manipulate the class list. Using classList is a convenient alternative to accessing an element's list of classes as a space-delimited string via element.
remove() The remove() function is used for removing the existing classes from the elements.
The classList. toggle() method supports adding and removing CSS classes whether they exist or not in your array with shorter lines of code.
I'm not aware of a "method" in the sense of a "function" associated with classList
. It has .add()
and .remove()
methods to add or remove individual classes, but you can clear the list in the sense of removing all classes from the element like this:
element.className = "";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With