title: How do I make this loop all children recursively?
body: <p>I have the following:</p>
  
  <pre><code>for (var i = 0; i &lt; children.length; i++){
     if(hasClass(children[i], "lbExclude")){
         children[i].parentNode.removeChild(children[i]);
     }
  };
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>for(var m = n.firstChild; m != null; m = m.nextSibling) {
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks!</p>
  
  <p>Update:</p>
  
  <p>I'm now using the following, according to answer suggestions. Is this the correct / most efficient way of doing so?</p>
  
  <pre class="lang-js prettyprint-override"><code>function removeTest(child) {
    if (hasClass(child, "lbExclude")) {
      child.parentNode.removeChild(child);
    }
  }
  
  function allDescendants(node) {
    for (var i = 0; i &lt; node.childNodes.length; i++) {
      var child = node.childNodes[i];
      allDescendants(child);
      removeTest(child);
    }
  }
  
  var children = temp.childNodes;
  for (var i = 0; i &lt; children.length; i++) {
    allDescendants(children[i]);
  };
  </code></pre>