HTML | DOM replaceWith() Method
The replaceWith() method replaces the a node in the children list of its parent with a set of Node or DOMString objects. DOMString objects are equivalent to Text nodes. Here, One child element is replaced by Other Child element.
- ChildNode: The ChildNode which is to be replaced.
- Node: The Node with which ChildNode is replaced.
Return Value: No return value.
In this example, I had replaced childNode named childPara (<p> element) with a node named childDiv (<div> element) by using this method.
In console, it can be seen:
- In line 12, Before applying replaceWith() method , outerHTML of parent element has <p> element as childNode.
- In line 16, After applying this method , parent element has <div> element replaced as ChildNode.
Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML course.