title: Passing loop variable as argument in element function
body: <p>Forgive the title, wasn't sure what to put.</p>
  
  <p>I have some code like:</p>
  
  <pre><code>var links=document.getElementsByTagName('a');
  for(var i=0;i&lt;links.length;i++){
      var cur=links[i];
      cur.onmouseover=function(){alert(i);};
  }
  </code></pre>
  
  <p>I remember seeing something like this before, but I have no clue how I would go about finding it. If another question like this has been asked, I would be far from surprised and would appreciate the link.</p>
  
  <p>edit: the problem is that it always alerts what 'i' is after the loop finishes. If there are two links, they all alert 2.</p>
  
  <p>edit: I remembered seeing it here: <a href="http://nathansjslessons.appspot.com/" rel="nofollow">http://nathansjslessons.appspot.com/</a>. Great few lessons, I suggest anyone who hasn't already to do them.</p>