[jQuery] Re: Eval issue ?

2009-07-01 Thread Ricardo
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); };

[jQuery] Re: Eval issue ?

2009-07-01 Thread James
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