Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10196 closed enhancement (duplicate)

Use native .cssList api in addClass, hasClass, removeClass, toggleClass prototypes

Reported by: Krinkle Owned by:
Priority: low Milestone: None
Component: attributes Version: git
Keywords: Cc:
Blocked by: Blocking:


The new specification has been out there for a little while and Google Chrome (13+) has already adopted this.

Try document.createElement('div').cssList and look at the proto:

  • add
  • contains
  • remove
  • toggle
  • .. more

I see two possible implementations:

  • in the method (ie. addClass) feature detection decides one or the other
  • a private or local group of methods is introduced that are set by reference to the native api if possible, and fallback to utility functions.

The latter is a bit more work, but better for performance.


class = {

add: elem.cssList ? elem.cssList.add : function( className, el ) { ... }, remove: elem.cssList ? elem.cssList.remove : function( className, el ) { ... }


and use like class.add.appy( elem, str );

A bit like isArray so to say (set by reference)

Change History (2)

comment:1 Changed 11 years ago by Rick Waldron

Component: unfiledattributes
Priority: undecidedlow
Resolution: duplicate
Status: newclosed

comment:2 Changed 11 years ago by Rick Waldron

Duplicate of #5087.

Note: See TracTickets for help on using tickets.