My question is about the example on this page: http://api.jquery.com/event.data/
<button> 0 </button>
<button> 1 </button>
<button> 2 </button>
<button> 3 </button>
<button> 4 </button>
<div id="log"></div>
JS:
var logDiv = $( "#log" );
for ( var i = 0; i < 5; i++ ) {
$( "button" ).eq( i ).on( "click", { value: i }, function( event ) {
var msgs = [
"button = " + $( this ).index(),
"event.data.value = " + event.data.value,
"i = " + i
];
logDiv.append( msgs.join( ", " ) + "<br>" );
});
}
In this demo, when I click one of the buttons, the output is like the following:
button = 0, event.data.value = 0, i = 5
what I don't understand is why "i = 5" here, shouldn't "i" be equal to "0" in this case?