Element.toggleAttribute

A new method named Element.toggleAttribute() allows toggling the existence of an element’s attribute in a way similar to Element.classList.toggle. An optional force parameter forces toggling the attribute even if it doesn't exist. This makes managing boolean attributes much simpler as the interface doesn't use strings as does Element.setAttribute().

Specification

Established standard

Status in Chromium

Blink>DOM


Enabled by default (tracking bug) in:

  • Chrome for desktop release 69
  • Opera release 56
  • Opera for Android release 56

Consensus & Standardization

After a feature ships in Chrome, the values listed here are not guaranteed to be up to date.

Owner

Last updated on 2018-07-19