How do I make this loop all children recursively?

Posted by Matrym on Stack Overflow See other posts from Stack Overflow or by Matrym
Published on 2010-04-26T08:53:04Z Indexed on 2010/04/26 8:53 UTC
Read the original article Hit count: 369

Filed under:
|
|
|
|

I have the following:

for (var i = 0; i < children.length; i++){
   if(hasClass(children[i], "lbExclude")){
       children[i].parentNode.removeChild(children[i]);
   }
};

I would like it to loop through all children's children, etc (not just the top level). I found this line, which seems to do that:

for(var m = n.firstChild; m != null; m = m.nextSibling) {

But I'm unclear on how I refer to the current child if I make that switch? I would no longer have i to clarify the index position of the child. Any suggestions?

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about children