title: Javascript DOM Selector
body: <p>I am learning JS and thought I had an ok grasp on it, until I finally reached the end of the line trying to work this one out. I have looked through the js reference and tried to debug myself, but I can't see where I am going wrong.</p>
  
  <p>I basically want the alert to show the href from the links when pressed left or right, I don't need anyone to hold my hand, but a little friendly hint at where I am going wrong would really help.</p>
  
  <p>Many thanks.</p>
  
  <p>The HTML:</p>
  
  <pre><code>&lt;nav class="portfolio-navigation clearfix col-sm-2"&gt;
     &lt;div class="portfolio-prev"&gt;
         &lt;a href="#" data-toggle="tooltip" class="tooltip-shortcode mt-tooltip" data-placement="top" title="#"&gt;
          &lt;i class="fa fa-chevron-left"&gt;&lt;/i&gt;
          &lt;/a&gt;
      &lt;/div&gt;
      &lt;div class="portfolio-next"&gt;
          &lt;a href="#" data-toggle="tooltip" class="tooltip-shortcode mt-tooltip" data-placement="top" title="#"&gt;
          &lt;i class="fa fa-chevron-right"&gt;&lt;/i&gt;
          &lt;/a&gt;
      &lt;/div&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>THE JS (With two seperate attempts):</p>
  
  <pre><code>document.onkeydown = function(e) {
      e = e || event;
      switch (e.keyCode) {
          case 37: 
              var linkprev = getElementsByClassName('portfolio-navigation')[0].getElementsByTagName("a")[0].innerHTML;
              alert(linkprev);
              break;
          case 38: alert(window.location.href); break;
          case 39: 
              var linknext = getElementsByClassName('portfolio-next')[0].getElementsByTagName("a")[0].getAttribute("href");
              alert(linknext);
              break;
          case 40: alert('down the drain'); break;        
      }
  };
  </code></pre>