Remove All Children from a Node

Description Javascript

This function removes all child nodes from a node.

e is either the id of the element as a string or an object reference.

Also requires xGetElementById function (should be available on this site) if you want to pass a string instead of an object.

The Code Download

  1. function removeChildrenFromNode(e) {
  2.     if(!e) {
  3.         return false;
  4.     }
  5.     if(typeof(e)=='string') {
  6.         e = xGetElementById(e);
  7.     }
  8.     while (e.hasChildNodes()) {
  9.         e.removeChild(e.firstChild);
  10.     }
  11.     return true;
  12. }


Added by JC on 11th November 2007


There are no comments about this snippet.

Post Comment Github Markdown Supported

You must be logged in to post a comment.

Login here to post a comment