PDA

View Full Version : How to clear an entire tree



robtcallahan
8 May 2007, 10:17 AM
Hi folks,

I have a folder tree that is working fine. Except that I need to be able
to clear it completely on certain user input. I just can't figure out how to do it.

I've tried:


for (var node in folderTreeRoot.childNodes) {
folderTreeRoot.removeChild(node);
}


But this doesn't seem to work. Actually I get an error.
Any suggestions?

Thanks in advance,
Rob

robtcallahan
8 May 2007, 11:20 AM
Well, I don't know if this is the proper way to do this, but I got it to work
using the following:



var chitlens = folderTreeRoot.childNodes;
for (var i=chitlens.length - 1; i>=0; i--) {
var node = chitlens[i];
folderTreeRoot.removeChild(node);
}



Sorry if this was a stupid question
Rob

vtswingkid
8 May 2007, 11:58 AM
good question.. I was wondering if there were a removeAll type method earlier today. I went another direction though, so I didn't pursue the answer.