+ 1
removing all child node "p" from parent node "demo" by loop or else for exp.
I want to remove all child nodes "p" from parent node "demo" by using removeChilde(child) <div id="demo"> <p>This is a paragraph.</p> <p>This is another paragraph.</p> </div> var parent = document.getElementById("demo"); var isChild = parent.hasChildNodes(); var i = 0; while(isChild){ parent.removeChild(parent.childNodes); i++; }
3 Antworten
+ 1
so basically your point is like
while(parent.firstChild){
parent.removeChild(parent.firstChild);
}
thanks.
+ 1
Yeah, that's how I would do it.
0
Try:
parent.removeChild(parent.firstChild)
instead.