title: How to use getElementsByTagName() to find all nested elements?
body: <p>I have the following HTML:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;&lt;title&gt;Title&lt;/title&gt;&lt;/head&gt;
    &lt;body&gt;
      &lt;div id='div2'&gt;
        &lt;a href='#'&gt;1&lt;/a&gt;
        &lt;div id='div1'&gt;
          &lt;a href='#'&gt;2&lt;/a&gt;
        &lt;/div&gt; 
      &lt;/div&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>... and the following Javascript code, which I'm running through Greasemonkey:</p>
  
  <pre><code>var nodes = document.body.getElementsByTagName('a');
  for (var i = 0; i &lt; nodes.length; i++) {
    var node = nodes[i];
    node.parentNode.removeChild(node);    
  }
  </code></pre>
  
  <p>I would expect it to find and remove all A tags; instead it finds the first, but not the second.  As far as I can tell it's having difficulty with the way the second A tag is nested.</p>
  
  <p>Could someone please let me know how to remove all the tags, using getElementsByTagName?  There are reasons I'd prefer not to use XPath if at all possible.</p>