[Bug 13999] DOMTokenList (e.g., element.classList): allow to add/remove multiple tokens at once

https://www.w3.org/Bugs/Public/show_bug.cgi?id=13999

--- Comment #13 from Erik Arvidsson <arv@chromium.org> 2012-03-05 18:11:23 UTC ---
(In reply to comment #11)
> Another possible approach would be to follow the precedent set by
> Array.prototype.push: make classList.add() a variable arity function - after
> all, it's essentially "push"ing onto the token list.
> 
> el.classList.add( token[, token... ] );
> 
> This also allows a user to do fun stuff like...
> 
> var classes = [ "foo", "bar", "baz" ];
> 
> // ... some program stuff that adds or substracts tokens from `classes`...
> 
> el.classList.add.apply( null, classes );

And with ES6 this will be even easier.

el.classList.add(...classes)

I'm opposed to space separated string since it is not well structured. Having
structure hidden in the string is less clear than taking multiple arguments.

Also, I can easily flip the join argument to use split

el.classList.add(...someString.split(/\s+/))

another reason why add should not take a space separated string is that
className already supports this:

el.className += ' ' + spaceSeparatedString;

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Monday, 5 March 2012 18:11:31 UTC