Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear element.classList

Tags:

javascript

dom

element.classList is of DOMTokenList type.

Is there a method to clear this list?

like image 389
warvariuc Avatar asked Feb 23 '13 11:02

warvariuc


People also ask

How do you clear a classList in Javascript?

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.

What is element classList?

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.

What does classList remove do?

remove() The remove() function is used for removing the existing classes from the elements.

What does classList toggle do?

The classList. toggle() method supports adding and removing CSS classes whether they exist or not in your array with shorter lines of code.


1 Answers

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 = ""; 
like image 62
nnnnnn Avatar answered Sep 20 '22 17:09

nnnnnn