toggleAttribute

fun toggleAttribute(qualifiedName: String, force: Boolean = definedExternally): Boolean(source)

The toggleAttribute() method of the Element interface toggles a Boolean attribute on the given element, removing it if present and adding it if not present.

MDN Reference