Parse for links that have target="new" and add an onclick event
<p>I have a web site that gets links generated dynamically. I would like to see if I can add an onclick event handler to track external links. I am looking to see links that has target="new" ( which means external to our site) and add the event handler</p>

<p>html code</p>

<pre><code> &lt;a target="new" href="http://twitter.com/cnn"&gt;CNN&lt;/a&gt;
</code></pre>

<p>The code I tried to test is not working. Let me know what is wrong in my code or should I some home append the onclick event to the external links?</p>

<p>Js code</p>

<pre><code>var links = document.getElementsByTagName("a");
for (var i=0; &lt;links.length; i++) { 
    if(links[i].target == 'new'){   
        links[i].onclick = function() {
            alert("Added onClick: " + links[i].href);        
        }
    }
}                                               
</code></pre>
