title: JavaScript loop through all elements with tagname, alert
body: <pre><code>var all = document.getElementsByTagName("a");
  for (var i=0, max=all.length; i &lt; max; i++) {
    alert(x.innerHTML);
  }
  </code></pre>
  
  <p>The purpose of this script is obvious: it tries to loop through all the elements with the tag name <code>a</code>, and alert the contents of each one.</p>
  
  <p>It doesn't run right.<br>
  It works fine, with one element, it alerts it's contents, but when there are more then one, it starts echoing <code>undefined</code> for each.</p>