Javascript for loop and alert
<p>I am looping through a list of links. I can correctly get the title attribute, and want it displayed onclick. When the page is loaded and when I click on a link, all of the link titles are alerted one by one. What am I doing wrong?</p>

<pre><code>function prepareShowElement () {
var nav = document.getElementById('nav');
var links = nav.getElementsByTagName('a');
for (var i = 0; i &lt; links.length; i++) {
    links[i].onclick = alert(links[i].title);
    }
}
</code></pre>
