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
@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.
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.
Have a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside