Bug Tracker

Modify

Ticket #10196 (closed enhancement: duplicate)

Opened 21 months ago

Last modified 21 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 21 months ago by rwaldron

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

comment:2 Changed 21 months ago by rwaldron

Duplicate of #5087.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.