Timeline for How to add a class to a given element?
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 8, 2016 at 14:56 | comment | added | Iulian Onofrei |
And it looks like DOMTokenList has a remove method too.
|
|
| Oct 8, 2016 at 14:54 | comment | added | Iulian Onofrei |
Isn't a.className = a.className + c; adding the class back? I don't get it.
|
|
| Sep 2, 2016 at 10:49 | comment | added | davidcondrey | @FezVrasta Under cross compatible I did use .add() but only after checking to see if it is available, hense cross compatible. For remove I did not bother to repeat myself so I did not include as many options. | |
| Aug 30, 2016 at 18:30 | review | Suggested edits | |||
| Aug 30, 2016 at 19:44 | |||||
| Mar 18, 2016 at 16:02 | comment | added | Fez Vrasta |
@Adam he used classList for everything except to remove classes, this is why I'm asking it.
|
|
| Mar 18, 2016 at 15:58 | comment | added | Adam | @FezVrasta classList isn't supported before IE 10, which still has a decent market share (+13% on netmarketshare.com). | |
| Jan 16, 2016 at 16:44 | comment | added | Fez Vrasta |
There's olso classList.remove(). Why didn't you used it? it's much faster than jQuery jsperf.com/remove-class-vanilla-vs-jquery
|
|
| Sep 6, 2015 at 12:47 | comment | added | Wilf |
Wow thanks :) Will the shorthand version (a.classList ? ...) have any speed difference compared to the normal one (if (a.classList) { ....)?
|
|
| Aug 2, 2015 at 7:20 | history | edited | davidcondrey | CC BY-SA 3.0 |
added 244 characters in body
|
| Dec 22, 2014 at 23:29 | history | answered | davidcondrey | CC BY-SA 3.0 |