javascript - Adding Action Listener Sets the Last Value Alone -
i trying add action listener several divs created dynamically. have use loop add action listener them.
this code:
for (var = 0; < mapdata.length; i++) { var marker = new google.maps.marker({ position: new google.maps.latlng(mapdata[i].lat, mapdata[i].long), icon: circlemaker, map: map }); var temp = mapdata[i].id; var temp_marker = marker; document.getelementbyid('sensor_'+temp).addeventlistener('mouseover', function() { //temp_marker.seticon(circlemakerhi); console.log("sensor: "+temp); }, false); } }
this loops prints last value of loop. if sensor_2 div hovered, should print sensor: 2 prints sensor: 7 7 mapdata.length.
Comments
Post a Comment