title: Javascript attach an onclick event to all link with href variable
body: <p>I am attempting to add an onclick function to all my links with the class of "external-link".  So I've successfully done it and did a test where anytime I click on one it alerts "it works" but how do return the href of that link into the function?  I'd like to throw in that variable where it says "<a href="http://www.example.com" rel="nofollow">http://www.example.com</a>".  I tried elements[i].href but it says it's undefined.</p>
  
  <pre><code>var elements = document.getElementsByClassName('external-link');
  for(var i = 0, len = elements.length; i &lt; len; i++) {
      elements[i].onclick = function () {
        trackOutboundLink(‘http://www.example.com’); return false;
      }
  }
  </code></pre>