[whatwg] DOMTokenList methods would be more useful with a space separated token list

Ian Hickson ian at hixie.ch
Wed May 2 15:13:00 PDT 2012


On Fri, 28 Oct 2011, David Håsäther wrote:
>
> It would be more useful if the DOMTokenList methods (contains, add, 
> remove, toggle) would take a space separated list of tokens. This is the 
> behavior most DOM libraries have when dealing with class names.
> 
> So, when setting two classes, instead of
> 
>   ele.classList.add("hey");
>   ele.classList.add("ho");
> 
> you could do
> 
>     ele.classList.add("hey ho");
> 
> Currently, the latter results in an INVALID_CHARACTER_ERR.
> 
> The behavior of all methods should be obvious I guess.

This has now moved to DOM Core. If you still want this I recommend filing 
a bug on that spec.

   http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html


On Fri, 28 Oct 2011, Mike Taylor wrote:
>
> I would prefer if it returned the DOMTokenList, to enable chaining like:
> 
>    foo.toggle('bar baz').remove('bat');

That makes for very hard to read code, IMHO. I much prefer:

   foo.toggle('bar');
   foo.remove('bat');

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list