Empty a DOM element
Short snippet of JavaScript to empty an HTML DOM element without memory leak:
while(el.lastChild) delete el.removeChild(el.lastChild);
Written by Maxime Thirouin
Related protips
3 Responses
looks similar to jQuery('something').empty()
.
search for empty: function
in the source to see how they do it
over 1 year ago
·
@zaus jQuery.fn.empty()
use a private method now https://github.com/jquery/jquery/blob/5179fa00b839ebc70ec38fb0cf6cb8f8c412f37e/src/manipulation.js#L96
But it use the same while trick not so long ago.
over 1 year ago
·
that's what i thought i was pointing to -- your ref is newer than latest, so it's a little different. i was only mentioning it as a comparison between your tip and how jQuery does it.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Dom
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#