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().
Status in Chromium
Enabled by default (tracking bug) in:
- Chrome for desktop release 69
Consensus & Standardization
Last updated on 2020-11-09