CharacterData.replaceWith()

The CharacterData.replaceWith() method replaces characters in the children list of its parent with a set of Node or DOMString objects. DOMString objects are inserted as equivalent Text nodes.

Syntax

replaceWith(...nodes)

Parameters

nodes
A set of Node or DOMString objects to replace.

Exceptions

Examples

Using replaceWith()

<p id="myText">Some text</p>
let text = document.getElementById('myText').firstChild;
text.replaceWith("Other text");
<p id="myText">Other text</p>

Specifications

Specification
DOM Standard (DOM)
# ref-for-dom-childnode-replacewith①

Browser compatibility

BCD tables only load in the browser

See also