JavaScript for loop goes too many times.
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example">Javascript closure inside loops - simple practical example</a>  </p>
</blockquote>



<p>Can someone tell me why the value of 'i' in this code prints out the number 4? the loop only goes to 3, however it will print 'i = 4' inside of the menu_feedback div.</p>

<pre><code>for(i=1; i&lt;=3; i++){
    $('#file_button'+i).hover(function (){
        $('#menu_feedback').html('i = '+i+'&lt;br/&gt;');
    }, function(){
        $('#menu_feedback').html('');
    });
}
</code></pre>

<p>.</p>

<pre><code>&lt;button type="button" id="file_button1"&gt;Door 1&lt;/button&gt;
&lt;button type="button" id="file_button2"&gt;Door 2&lt;/button&gt;
&lt;button type="button" id="file_button3"&gt;Door 3&lt;/button&gt;

&lt;div id="menu_feedback"&gt;&lt;/div&gt;
</code></pre>
