See http://jsfiddle.net/tAfkU/
When I'm looping through an array, how can I refer to the correct element of the array when I've bound callbacks in the loop?
var items = ["a", "b", "c"];
for(var i in items) {
var this_item = items[i];
var new_li = $('<li>'+this_item+'</li>');
new_li.bind('click', function() {
alert(this_item); // this always alerts "c"
});
$('.container').append(new_li);
}