title: DOM scripting getElementsByClassName (for links)
body: <p>I am practicing DOM Scripting (no real-life problem but rather practice and theory, I know how to achieve this with jQuery of course)
  So, I am trying to improve and understand the following:</p>
  
  <p>I have some links with classes and I am attaching event on them:</p>
  
  <pre><code>&lt;a href="http://www.google.com" class="popup"&gt;click&lt;/a&gt;
  &lt;a href="http://www.test.com" class="popup"&gt;click2&lt;/a&gt;
  &lt;a href="http://www.abc.com" class="popup"&gt;click3&lt;/a&gt;
  &lt;a href="http://www.google.com" class="no"&gt;click4&lt;/a&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>window.onload = prepareLinks;
  
  function prepareLinks() {
      var links = document.getElementsByTagName("a");
      for (var i = 0; i &lt; links.length; i++) {
          if (links[i].getAttribute("class") == "popup") {
              links[i].onclick = function () {
                  popUp(this.getAttribute("href"));
                  return false;
              }
          }
      }
  }
  
  
  function popUp(winURL) {
      window.open(winURL, "popup", "width=320,height=480");
  }
  </code></pre>
  
  <p>That works fine. I got it from a book basically. Now I want to improve it by making use of getElementsByClassName. I went on to write:</p>
  
  <pre><code>window.onload = prepareLinks;
  
  function prepareLinks() {
      var links = document.getElementsByTagName("a");
      var popups = links.getElementsByClassName("popup");
      for (var i = 0; i &lt; popups.length; i++) {
          popups[i].onclick = function () {
              popUp(this.getAttribute("href"));
              return false;
          }
      }
  }
  
  
  function popUp(winURL) {
      window.open(winURL, "popup", "width=320,height=480");
  }
  </code></pre>
  
  <p>But I got error:
  Uncaught TypeError: Object # has no method 'getElementsByClassName'</p>
  
  <p>Apparently links is a NodeList so I can't use the getElementsByClassName on it. Which I don't really understand...
  Can you help on how I could do this, and whether or not the first version of the script is good? (performance wise). Thanks. </p>