jquery/standards — Issue #13: classList is not usable yet
Author: paulirish
Created: 2011-10-25 19:09:43+00:00
State: open

There are issues at the spec level and the browser level that make classList untenable for authoring in javascript and authors of libraries.

## Specific issues

* The API makes it too arduous to work with as a replacement for className manipulation. The authoring experience is very awkward.
* Performance of the method calls isn't good enough for libraries to consider adoption.

## Specific Suggestions

* Return value of classList methods should be a `DOMTokenList` instead of `undefined`. This allows chaining.
```js
elem.classList.remove('oldnbusted').add('newhostness');
```
* Methods need to take multiple class arguments:
```js
elem.classList.remove('classone classtwo')
```
* Performance in implementations need to improve. [An effort was made in jQuery](https://github.com/jquery/jquery/pull/228) to add classList support but performance was inferior to className manip: http://jsperf.com/classlist-vs-addclass/2
* On perf, Resig concluded:

> So it seems like this doesn't provide any perf benefit over our current solution (which is unfortunate) - thus we'll probably want to hold off on landing this until we can get some appreciable gains.

* On perf, I asked a WebKit engineer and he said:

> One of the problem with almost all the js solutions I've seen is that they are not complete. In other words they fail with some input data. If it turns out that a js solution that is complete is faster than the webkit one we should probably look at this again.

> For completeness see [Webkit's classList layoutTests](http://www.google.com/codesearch/p?hl=en#OAMlx_jo-ck/src/third_party/WebKit/LayoutTests/fast/dom/HTMLElement/script-tests/class-list.js&q=class-list&exact_package=chromium&sa=N&cd=2&ct=rc)

## Notes

Spec on classList: http://www.w3.org/TR/html5/common-dom-interfaces.html#domtokenlist-0

+@miketaylr