DOM & Events - Adding & Removing Elements !!!Please help!!!
DOM & Events - Adding & Removing Elements !!!Please help!!! <div id="demo">some content</div> <div id="demo2"> <p id="p1">This is a paragraph.</p> <p id="p2">This is another paragraph.</p> </div> <div id="demo3"> <p id="p1">This is a paragraph.</p> <p id="p2">This is another paragraph.</p> </div> //calling the function in windo.onload to make sure the HTML is loded window.onload = function() { //creating a new paragraph var p = document.createElement("p"); var node = document.createTextNode("some new text"); //adding the text to the paragraph p.appendChild(node); var div = document.getElementById("demo"); //adding the paragraph to the div div.appendChild(p); }; document.write("<br/>"); //calling the function in window.onload to make sure the HTML is loaded window.onload = function() { var parent = document.getElementById("demo2"); var child = document.getElementById("p1"); parent.removeChild(child); }; document.write("<br/>"); //calling the function in window.onload to make sure the HTML is loaded window.onload = function() { var p = document.createElement("p"); var node = document.createTextNode("This is new"); p.appendChild(node); var parent = document.getElementById("demo3"); var child = document.getElementById("p1"); parent.replaceChild(p, child); }; why does this not all work on the same page together when I run it? can someone please help me with this question what am I doing wrong?