assigning variables to DOM event listeners when iterating
Posted
by ptrn
on Stack Overflow
See other posts from Stack Overflow
or by ptrn
Published on 2010-06-01T19:24:47Z
Indexed on
2010/06/01
19:33 UTC
Read the original article
Hit count: 322
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?
© Stack Overflow or respective owner