For example:
var items = jq(".li");
for(var i=0; i<items.length; i++){
var item = jq(items[i]);
item.click(function(i){
console.log("i: ", i);
});
}
The problem with this code is that when the click event is triggered, i debugs undefined. I imagine that this happens because it is at that moment when it will look for the value of i which no longer exists because the loop has ended.
How can I solve this? I can not pass a parameter to an anonymous function.
Thanks in advance.