Event handler in a loop
Event handler in a loop
I've many div with sequence of ids like d1 d2 d3 ...
and I need to listen to their click event so I'm using a loop to add an event handler to them,
Here it's my code:
for(var i = 0; i < $ds.length; i++){
var $d = $ds[i];
var xFunc = function(e){
document.title = "d: "+$d;
};
//$('#d'+$d).click(xFunc);
}
But when I click on each of them always the title goes to "d: 4" where 4 is the last value in $ds.
Any one has any solution for this issue?