$("#div" + i).click(
function() {
alert(i);
}
);
It's because it's using the value of i as a closure. i is remembered through a closure which increases at every stage of the foor loop.
$("#div" + i).click(function(event) {
alert($(event.target).attr("id").replace(/div/g, ""));
});