Sometimes, we want to clear all divs inside a parent div with JavaScript.
In this article, we’ll look at how to clear all divs inside a parent div with JavaScript.
How to clear all divs inside a parent div with JavaScript?
To clear all divs inside a parent div with JavaScript, we set the innerHTML
property of the parent div to an empty string.
For instance, we write
document.getElementById("masterdiv").innerHTML = "";
to select the parent div with getElementById
.
Then we set its innerHTML
property to an empty string to clear the divs inside it.
Conclusion
To clear all divs inside a parent div with JavaScript, we set the innerHTML
property of the parent div to an empty string.