classList
is not a function, but a DOMTokenList
object ( see also ).
console.info(typeof document.querySelector('div').classList); // object
<div></div>
Methods :
add()
- Adds a value to the DOMTokenList
object, if not present.
contains()
- Checks whether the DOMTokenList
object DOMTokenList
passed value or not.
item()
- Returns the value at the specified index.
remove()
- Removes a value from the DOMTokenList
object, if any.
toggle()
- If the DOMTokenList
contains the value passed to the method, it will be removed, otherwise it will be added.
They are more, but it is the most used
Properties :
length
- The number of elements (or characters).