Skip to content

classList is not usable yet #13

@paulirish

Description

@paulirish

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.
elem.classList.remove('oldnbusted').add('newhostness'); 
  • Methods need to take multiple class arguments:
elem.classList.remove('classone classtwo')
  • Performance in implementations need to improve. An effort was made in jQuery 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

Notes

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

+@miketaylr

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions