The classList Property
About
The classList
property is defined on HTMLElements
and is an object which allows one to cleanly modify which classes apply to an element rather than by directly modifying the className
property.
classList
is of type DOMTokenList
, which can be manipulated by the following methods.
-
add(string className)
applies the specified class to the element. -
remove(string className)
removes the specified class from the element. -
toggle(string className)
toggles the application of the specified class on the element. -
contains(string className)
returns a boolean representing whether the class is present on the element.
References
- https://developer.mozilla.org/en/DOM/
element.classList - https://developer.mozilla.org/en/DOM/
element.className - http://www.whatwg.org/specs/web-apps/
current-work/multipage/elements.html #dom-classlist