Add Remove DOM JS
by anoopsuda
HTML
<button onclick="create()">Create</button>
<button onclick="create2()">Create</button>
<button onclick="remove()">Remove</button>
JavaScript
var heading = document.createElement("h1");
var heading2 = document.createElement("h2");
function create(){
heading.innerHTML = "Hello World";
document.body.appendChild(heading);
}
function create2(){
heading2.innerHTML = "Hello World 2";
document.body.appendChild(heading2);
}
function remove(){
document.body.removeChild(heading);
}