That’s because you’re sharing the same counter variable for all click handlers and it is whatever it ends up being at the end of the loop. Instead, use the one passed into the loop (the index parameter of the .each() that’s already there), like this:
$('.thumb').each(function (i) {
$(this).click(function () {
alert (i+1); //index starts with 0, so add 1 if you want 1 first
});
});
You can test it here.