title: removechild loop exits before finish
body: <p>I have the following piece of code that finds all elements in the document with classname foo and then removes them all</p>
  
  <pre><code>        function(doc) {
              var items = doc.getElementsByClassName('foo');
              alert(items.length);
              if(items.length&gt;0) {
                  for(var i=0;i&lt;items.length;i++) {
                      alert(i);
                      doc.body.removeChild(items[i]);
                  }
          }
  </code></pre>
  
  <p>Forexample, the items.length is 3 and the function exits after running one loop and when the length is 8 it exits at 3. Any help would be greatly appreciated. Also, when I run the function again and again it does eventually remove all elements. </p>