- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Removing Elements
JavaScript DOM
JavaScript Removing Elements
removetakes an element off the page, andremoveChilddoes the same from the parent.
remove is the modern, direct way.
removeChild is older and still very common in existing code.
Example
Example
javascript
document.body.innerHTML = '<p id="demo">Goodbye</p>';
document.getElementById("demo").remove();
console.log(document.querySelectorAll("p").length);