[whatwg/dom] [idea] toggleAttribute with detault value when attribute is added. (#939)

For example,

```js
// Assume we start with `el` already having the `foo` attribute:
el.toggleAttribute('foo', 'bar') // no longer has attribute `foo`
el.toggleAttribute('foo', 'bar') // now has attribute `foo` with value `bar`
el.toggleAttribute('foo', 'bar') // no longer has attribute `foo`
el.toggleAttribute('foo', 'bar') // now has attribute `foo` with value `bar`
```

- If the attribute exists, remove it. This is similar to calling `removeAttribute('foo')` while the attribute exists.
- If the attribute does not exist, add it, with the given value. This is similar to calling `setAttribute('foo', 'bar')` while the attribute does not exist.

The above code would be equivalent to this:

```js
// Assume we start with `el` already having the `foo` attribute:
el.removeAttribute('foo') // no longer has attribute `foo`
el.setAttribute('foo', 'bar') // now has attribute `foo` with value `bar`
el.removeAttribute('foo') // no longer has attribute `foo`
el.setAttribute('foo', 'bar') // now has attribute `foo` with value `bar`
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/939

Received on Wednesday, 30 December 2020 00:12:02 UTC