Implementation of classList attribute (DOMTokenList interface). Depends on Array Generics.
var element = document.documentElement;
// add class
element.classList.add("root");
// remove class
element.classList.remove("root");
// toggle class
element.classList.toggle("root");
// test class
element.classList.contains("root");
Just include into your document:
<script src="path_to/array.generics.min.js"></script>
<script src="path_to/element.classlist.min.js"></script>
- Browsers that natively supports classList does not pass all tests (at least at the moment).
- This shim does not work in Internet Explorer versions less than 8.