1var myDiv = document.getElementById("myDivID");
2 myDiv.innerHTML = "";//remove all child elements inside of myDiv
1<script>
2function removeAllChildNodes(parent) {
3 while (parent.firstChild) {
4 parent.removeChild(parent.firstChild);
5 }
6}
7
8const container = document.getElementById('container');
9removeAllChildNodes(container);
10</script>
11
12<div id="container">
13 <p>All elements inside this container will be deleted,</p>
14 <p>when removeAllChildNodes(container) is run.</p>
15</div>
1parent.querySelectorAll("*").forEach(child -> child.remove());
2
3//Change the value of * if there is a specific class you want to remove
4//otherwise leave the * for removing all child elements.