How to replace a element using javascript

Posted by Manideepgoud under JavaScript category on | Points: 40 | Views : 1179
We use replaceChild() to replace elements

 <div id="div1">
<p id="p1">TechFunda.</p>
<p id="p2">DotNetFunda</p>
var a = document.createElement("p");
var b = document.createTextNode("ITFunda");
var c = document.getElementById("div1");
var d = document.getElementById("p1");
c.replaceChild(a, d);

We created element p with text as ITFunda by using replaceChild(a,d); it replaces the value TechFunda with ITFunda

Comments or Responses

Login to post response