Skip to main content

Bug Tracker

Side navigation

#10196 closed enhancement (duplicate)

Opened September 03, 2011 03:21AM UTC

Closed September 03, 2011 03:33AM UTC

Last modified September 03, 2011 03:33AM UTC

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:
Description

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.

ie.

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)

Attachments (0)
Change History (2)

Changed September 03, 2011 03:33AM UTC by rwaldron comment:1

component: unfiledattributes
priority: undecidedlow
resolution: → duplicate
status: newclosed

Changed September 03, 2011 03:33AM UTC by rwaldron comment:2

Duplicate of #5087.