Closures in a loop are causing me problems. I think I have to make another function that returns a function to solve the problem, but I can\'t get it to work with my jQuery
See the bind method.
$('#button'+i).bind('click', {button: i}, function(event) {
foo(event.data.button);
});
From the docs:
The optional eventData parameter is not commonly used. When provided, this argument allows us to pass additional information to the handler. One handy use of this parameter is to work around issues caused by closures