This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23712 - DOMTokenList needs a way to conditionally set or remove
Summary: DOMTokenList needs a way to conditionally set or remove
Status: RESOLVED WORKSFORME
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-04 00:55 UTC by Ian 'Hixie' Hickson
Modified: 2013-11-04 12:47 UTC (History)
5 users (show)

See Also:


Attachments

Description Ian 'Hixie' Hickson 2013-11-04 00:55:42 UTC
http://dom.spec.whatwg.org/#interface-domtokenlist

It'd be nice if we could change this:

  if (foo != e.classList.has('foo'))
     e.classList.toggle('foo');

...to:

   e.classList.set('foo', foo);

...or some such.
Comment 1 Ian 'Hixie' Hickson 2013-11-04 01:10:35 UTC
Oh, I see, toggle() does this if given a second argument.
Comment 2 Glenn Maynard 2013-11-04 02:20:27 UTC
FWIW, I didn't know it did that, and I've always overridden .set to have that behavior.  I think it makes more intuitive sense on .set than on .toggle, eg. classList.set("foo", true).

But it seems to be implemented already on .toggle in Chrome (not Firefox), and I guess it's not enough of a difference to change it now.
Comment 3 Boris Zbarsky 2013-11-04 12:47:30 UTC
> (not Firefox)

Uh... Firefox 24 and later implement it.