JS Error while removing the node

Hi ,

when i try to use the below line to remove the child, it is throwing an error



I want to sort the child nodes in alpha order, but how to remove and append the child nodes - is this a correct solution.



for (var i=1; i<Count; i++){

     nodeName = Nodes[i].getElementsByTagName(“span”)[0].innerHTML;

     sortArray[i] = nodeName;     

}

sortArray.sort();



for (var i=0; i<=Count; i++){     

itemObject.parentObject.htmlNode.childNodes[0].childNodes[i].removeChild(itemObject.tr);

     }



Node was not found" code: "8



Regards.

The tree contains a pretty complex inner structure so using manual HTML operation is not the safe way
In case of item sorting , tree have ready to use solution
    ext/dhtmlxtree_sb.js
    tree.sortTree(id,order,levels)