HTML DOMTokenList replace() Method
- Previous Page remove()
- Next Page supports()
- Go to Parent Page HTML DOMTokenList
Definition and Usage
The replace() method replaces the token in the DOMTokenList.
Example
Example 1
Replace with another CSS class:
const list = element.classList; list.replace("myStyle", "newStyle");
Example 2
Add the "myStyle" class to the element:
const list = element.classList; list.add("myStyle");
Example 3
Remove the "myStyle" class from the element:
const list = element.classList; list.remove("myStyle");
Example 4
Toggle the open/close of "myStyle":
const list = element.classList; list.toggle("myStyle");
Syntax
domtokenlist.replace(old, new)
Parameters
Parameters | Description |
---|---|
old | Required. The tag to be replaced with. |
new | Required. The tag to be replaced. |
Return Value
Type | Description |
---|---|
Boolean Value | Returns true if the tag is replaced, otherwise false. |
Browser Support
domtokenlist.replace() is an ECMAScript7 (ES7) feature.
All modern browsers support ES7 (JavaScript 2016):
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
Internet Explorer or Edge 17 (or earlier versions) do not support domtokenlist.replace().
Related Pages
- Previous Page remove()
- Next Page supports()
- Go to Parent Page HTML DOMTokenList