1var myDiv = document.getElementById("myDivID");
2 myDiv.innerHTML = "";//remove all child elements inside of myDiv
1// Get the <ul> element with id="myList"
2let list = document.getElementById("myList");
3
4// As long as <ul> has a child node, remove it
5while (list.hasChildNodes()) {
6 list.removeChild(list.firstChild);
7}
1function deleteChild() {
2 let e = document.querySelector("ul");
3
4 //e.firstElementChild can be used.
5 let child = e.lastElementChild;
6 while (child) {
7 e.removeChild(child);
8 child = e.lastElementChild;
9 }
10 }
11 let btn = document.getElementById(
12 "btn").onclick = function() {
13 deleteChild();
14 }