Snippets v2

Languages
My Snippets

Remove All Children from a Node Login or Register to Bookmark this snippet

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. }
Credits Contact JC

Added by JC on 11th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment