We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 03/13/07


Tagged

DOM remove childnodes


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

vali29


Remove All childNodes


Published in: JavaScript 


This while loop will remove all childNodes from a selected element.

  1. var holder = document.getElementById("whateverDiv");//the holder div
  2.  
  3. while(holder.hasChildNodes()){
  4. holder.removeChild(holder.lastChild);
  5. }

Report this snippet 

You need to login to post a comment.