[whatwg] classList.toggle()
Martin Atkins
mart at degeneration.co.uk
Tue May 1 00:05:49 PDT 2007
Maciej Stachowiak wrote:
>
>
> How about about adding a toggle() operation to classList? Adds the token
> if not present, removes it if present. This would be useful for script
> code that dynamically manipulates classes to cause style changes.
>
It's been my experience that toggles are troublesome. In order for a
call to toggle() to be successful -- where by successful I mean that it
makes the change you intended -- you need to know the state ahead of
time. If you have two distinct scripts "toggling" the same value,
they're going to get out of step and think they're turning on when
they're turning off.
Or did you have a use-case in mind where it doesn't matter what the end
result is as long as it's not what it was before?
More information about the whatwg
mailing list