JS variable scope missunderstanding
<p>I have a little problem:
slideHelpers.total = 4</p>

<pre><code>for (i=1;i &lt;= slideHelpers.total; i++) {
    $('&lt;a href="#"&gt;' + i + '&lt;/a&gt;').bind('click', function(){ alert('go to the ' + i + ' slide')}).appendTo('.slideaccess')
}
</code></pre>

<p>the alert gives out 5 what is logic, because when the function click triggers i is actually 5. But i would like to have the same i as in my <code>&lt;a&gt;</code> tag. What is the best way to handle this?</p>

<p>I could put i in the data() of the <code>&lt;a&gt;</code> tag for example but i am sure there is a easier way. </p>
