Reputation: 16017
I want to ask if I want to remove an HTML element's children but I don't necessarily want to loop through them, would setting the parent's ìnnerHTML
to null or an empty string remove the children from memory, not just from the visual part of the document?
Upvotes: 0
Views: 1435
Reputation: 18997
Yes, it will completely remove children.
For example, you have:
<div id="a_div">
<input type='button'><br>
<img src='image.png'>
</div>
Then
document.getElementById("a_div").innerHTML="<input type='button'><br><img src='image.png'>";
So if you set innerHTML to ""
(document.getElementById("a_div").innerHTML="";
), then a_div
will be
<div id="a_div">
</div>
Upvotes: 1
Reputation: 1342
If you are using jQuery then empty()
function used on the parent element will remove the elements from the DOM.
Upvotes: 0