replace

fun replace(token: T, newToken: T): Boolean(source)

The replace() method of the DOMTokenList interface replaces an existing token with a new token.

MDN Reference