HTML DOMTokenList replace()
❮ The DOMTokenList ObjectExamples
Replace a CSS class with another:
const list = element.classList;
list.replace("myStyle", "newStyle");
Try it Yourself »
Add a "myStyle" class to an element:
const list = element.classList;
list.add("myStyle");
Try it Yourself »
Remove the "myStyle" class from an element:
const list = element.classList;
list.remove("myStyle");
Try it Yourself »
Toggle "myStyle" on and off:
const list = element.classList;
list.toggle("myStyle");
Try it Yourself »
Description
The replace()
method replaces a token in a
DOMTokenList.
See Also:
Syntax
domtokenlist.replace(old, new)
Parameters
Parameter | Description |
old | Required. The token to replace. |
new | Required. The token to replace with. |
Return Value
Type | Description |
Boolean | true if the token was replaced, otherwise false . |
Browser Support
domtokenlist.replace()
is an ECMAScript 2017 feature.
ES2017 is supported in all modern browsers since September 2017:
Chrome 58 | Edge 15 | Firefox 52 | Safari 11 | Opera 45 |
Apr 2017 | Apr 2017 | Mar 2017 | Sep 2017 | May 2017 |
domtokenlist.replace()
is not supported in Internet Explorer.
❮ The DOMTokenList Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.