← Back to release summary

Element.toggleAttribute

Category
DOM
Type
New or changed feature
Status
Enabled by default (Chrome 69)
Intent stage
None

Summary

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().

Standards & signals

View on chromestatus.com