Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Removing All Child Nodes From Parent

    Hi,

    I'm using the following code to remove all child nodes from a parent. I guess it's another example that breaks IE(7). Can someone suggest an IE-tolerant alternative.

    Thanks, windy


    Code:
    var strID = 'parentNodeName';
    var parent =  document.getElementById(strID);
    removeChildNodes(parent);
    
    function removeChildNodes(parent){
        while(parent.hasChildNodes()){
            parent.removeChild(parent.childNodes[0]) //--> IE error 'Not found'
        }
    }

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,990
    Thanks
    120
    Thanked 76 Times in 76 Posts
    this is what I have somewhere, didn't test it for your error. Try it.
    Code:
         // remoove all  inner elements of  TDnodeObj
        while(TDnodeObj.firstChild) TDnodeObj.removeChild(TDnodeObj.firstChild);
    Regards

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, that seems to work

    w


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •