Ticket #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: | ||
| 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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
