[whatwg] DOMTokenList methods would be more useful with a space separated token list
Mike Taylor
michaelaarontaylor at gmail.com
Fri Oct 28 09:07:48 PDT 2011
On Fri, Oct 28, 2011 at 11:52 AM, Philip Jägenstedt <philipj at opera.com>wrote:
> On Fri, 28 Oct 2011 12:58:01 +0200, David Håsäther <hasather at gmail.com>
> 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.
>>
>
> +1, but what should toggle return?
>
> toggle("a") returns true if "a" was added, which is equivalent to
> !contains("a") on the initial string or contains("a") on the final string.
> For toggle("a b"), !contains("a b") on the initial string may not be the
> same as contains("a b") on the final string, so which should it be? Put
> simpler, should it return true if any token is added or if all tokens are
> added?
I would prefer if it returned the DOMTokenList, to enable chaining like:
foo.toggle('bar baz').remove('bat');
Same for the rest of the DOMTokenList methods, as well.
foo.add('bar').remove('baz');
See also https://github.com/jquery/standards/issues/13 for relevant
discussion.
More information about the whatwg
mailing list