That is because you are not preserving i by making a closure
for (var i = 1; i <= 10; i++) {
(function(index){
$('#chatlist').append($("<div class='chatlist_cell'>" + index + "</div>").click(function() {
alert(index)
}))
})(i);
}
Another option would be to use each()
$.each(Array(10), function(index) {
$("<div class='chatlist_cell'>" + (index + 1) + "</div>").appendTo('body').click(function() {
console.log(index + 1)
});
});
$.each(Array(10), function(index) {
$("<div class='chatlist_cell'>" + (index + 1) + "</div>").appendTo('body').click(function() {
console.log(index + 1)
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>