Testing the HTML5 Element.classList property
HTML5 introduces support for a new property applying to each Element on your page, "classList". This property adds a convenient interface to the DOM allowing you to modify the element's classes with ease, similar to what jQuery has been doing as no native interface was available.
interface DOMTokenList // used for classList
{
readonly integer length;
getter string item (index);
boolean contains (className);
void add (className);
void remove (className);
boolean toggle (className);
stringifier string toString ();
}
Testing support for the individual properties and methods in your browser:
- lengthfailed
- item ()failed
- contains ()failed
- add ()failed
- remove ()failed
- toggle ()failed
- toString ()failed
If you're a web developer, and want to use this property without waiting for support among all browsers since Internet Explorer 8, the Mozilla Team has made a JavaScript implementation which you can use in your scripts. You'll still have to a library like jQuery for IE6 and IE7 support though.