Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 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:

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)

Change History (2)

comment:1 Changed 6 years ago by rwaldron

  • Component changed from unfiled to attributes
  • Priority changed from undecided to low
  • Resolution set to duplicate
  • Status changed from new to closed

comment:2 Changed 6 years ago by rwaldron

Duplicate of #5087.

Note: See TracTickets for help on using tickets.