If you put the loop inside a function, you'll have access to the 'i'
variable because of scoping:
// *** just for demonstration, this is bizarre ***
for (var i=0; i < TAGS.length; i++) {
(function(i){
TAGS[i].click( function(event) {
alert(B[i]);
});
})(i);
};
How about changing the technique a bit like:
for (var i=0; i < TAGS.length; i++) {
TAGS[i].data('count', i)
.click(function(event) {
alert( B[$(this).data('count')] );
});
}
Basically it stores the value of 'i' with the element using .data(),
and you can retrieve
2 matches
Mail list logo