Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Intent to ship: Element.toggleAttribute

61 views
Skip to first unread message

Jonathan Kingston

unread,
Jun 27, 2018, 7:14:58 PM6/27/18
to dev-platform
Many JavaScript libraries exist to toggle attributes in the DOM. By moving
this to the web platform we will simplify the boilerplate developers have
to use.

This method will behave similar to Element.classList.toggle, this will
allow developers to pass an argument of the attribute to toggle:

element.toggleAttribute(“disabled”);

It also permits an optional second argument for the state of the boolean to
set:

inputElement.toggleAttribute(“checked”, isChecked);

Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1469592

Link to standard: https://dom.spec.whatwg.org/#dom-element-toggleattribute

Platform coverage: This will be exposed to all platforms.

Estimated or target release: Firefox 63

Is this feature enabled by default in sandboxed iframes? N/A

DevTools bug: N/A

Do other browser engines implement this? Yes

Chrome intent to ship:
https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/mAWBTaANvmE/OgaCRH04BAAJ

Edge are considering
https://github.com/whatwg/dom/issues/461#issuecomment-398206390

Browsers bugs:

https://bugs.chromium.org/p/chromium/issues/detail?id=854960

https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/17981545/

https://bugs.webkit.org/show_bug.cgi?id=186883

web-platform-tests: https://github.com/web-platform-tests/wpt/pull/11603

Secure contexts:

This feature isn’t restricted to Secure Contexts, this is mostly due to
providing similar behaviour with other element APIs such as hasAttribute
and setAttribute. There aren’t any increased risks in exposing this API to
insecure contexts and the behaviour can easily be implemented in a
JavaScript shim. It seems overly onerous on the web to mandate
SecureContext only for this when it could cause unexpected behaviour to
remove this API on an insecure connection.


In Firefox 63 I intend to turn Element.toggleAttribute on by default. Other
UAs are interested in implementing this feature as highlighted in the
standards thread: https://github.com/whatwg/dom/issues/461.

Bug implementing and enabling this feature: (
https://bugzilla.mozilla.org/show_bug.cgi?id=1469592)

Boris Zbarsky

unread,
Jun 27, 2018, 10:07:01 PM6/27/18
to
On 6/27/18 7:14 PM, Jonathan Kingston wrote:
> Is this feature enabled by default in sandboxed iframes? N/A

It is, yes.

-Boris
0 new messages