3 ms·
That won't work either. You're still setting the variable to the global variable i. The only way I can think of doing this is as follows els[i].addEventListene
by archgoon 16y ago
That won't work either. You're still setting the variable to the global variable i. The only way I can think of doing this is as follows
els[i].addEventListener('click',function(k){function(){alert(k)}}(i));
EDIT: See lhorie's suggestion below for a much cleaner way of doing this. http://news.ycombinator.com/item?id=2124532 http://news.ycombinator.com/item?id=2124532