assigning variables to DOM event listeners when iterating
- by ptrn
I'm thinking there's something basic stuff I'm missing here;
for (var i=1; i<=5; i++) {
var o = $('#asd'+i);
o.mouseover(function() {
console.info(i);
});
}
When hovering over the five different elements, I always get out the last value from iteration; the value 5. What I want is different values depending of which element I'm hovering, all from 1 to 5.
What am I doing wrong here?