[jQuery] passings variables to callback functions
I was wondering if there are ways to pass variables of non-global
scope to callback function like in the situation below. I've run into
this situation before and imagine it comes up often. So passing the
photo[i]['id'] variable to imgselect is the issue here since at the
time the event is triggered, it does not have the same value as it
would at the time of binding.
for (i=0;i<photo.length;i++) {
var newimg = document.createElement('img');
$(newimg).attr('src',photo[i]['url']);
$(newimg).bind("click", imgselect(photo[i]['id']));
$('#photoholder').append(imgdiv);
}