Now we will create another span element and add some text to it.
We created another element p with some text content in it, then append the p element as child element to div. replaceWith() method is used to replace a node or an element with another.
Example of using replaceWith() const div = document.createElement("div") Ĭonst txt = document.createTextNode("Text Content") Ĭonst span = document.createElement("span") Ĭonst newTxt = document.createTextNode("New Text Content") Īt the first, we created a parent element div. jQuery replaceWith not working without DOM Code Answer Jadmin I am trying to do some element manipulation on a Node.js server where I need to take a string of HTML, then replace some of the nodes with other node types. In simpler terms, the javascript replaceWith() method will replace an Element or Node with other. The replaceWith() function in javascript is used to replace an Element in the child list of the parent with a set of Node or DOMString objects.