Cross-browser element class manipulation (including support for SVG elements),
utilizing the native classList when possible.
npm install dom-classlist
var classList = require('dom-classlist');
classList(el).toArray();
// => [ 'foo', 'bar' ]
classList(el).add('baz');
classList(el).remove('bar');
classList(el).remove(/^foo/);
classList(el).toggle('bar');
// => true
classList(el).toggle('bar');
// => false
classList(el).contains('bar');
// => falseReturn an array of the element's classes.
Add the class to the class list.
Remove the class from the class list, or remove all class names matching the regex regular expression.
Toggle the class in the class list.
Check if the class is present in the class list.
- Google Chrome
- Firefox 4+
- Internet Explorer 8+
- Safari 5+
- Opera
