Possible Duplicate:
Javascript closure inside loops - simple practical example
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.
for(i=1; i<=3; i++){
$('#file_button'+i).hover(function (){
$('#menu_feedback').html('i = '+i+'<br/>');
}, function(){
$('#menu_feedback').html('');
});
}
.
<button type="button" id="file_button1">Door 1</button>
<button type="button" id="file_button2">Door 2</button>
<button type="button" id="file_button3">Door 3</button>
<div id="menu_feedback"></div>