Javascript DOM Element Replace Child
<html> <head> <title>Replacing Nodes</title> </head>// w w w . j av a2 s.c om <body> <div> <p id="myParagraph">This is a test</p> </div> <script type="text/javascript"> let newParagraph = document.createElement("p"); newParagraph.innerText = "I'm a new node!"; newParagraph.textContent = "I'm a new node!"; let oldParagraph = document.getElementById("myParagraph"); oldParagraph.parentNode.replaceChild(newParagraph, oldParagraph); </script> </body> </html>