I’m at loss at how to describe this without code, so here it goes:
$('.colors').each(function() {
$.getJSON('my.json', function(data) {
$(this).css('color', data.color);
});
});
I want the body of the getJSON callback to reference the value of this in the parent (each callback) scope.
This code will not work, because this will not be what it was outside the getJSON callback. Even if I try to place it in a variable, it will not work because only one variable will be shared by all callbacks, instead of one per iteration of the loop.
How can I achieve this?
Have a look at proxy