i can think of easier ways to do what you are trying, but this'll work for you:
EDIT: Sorry i thought it was clear i was supplying a replacement for the line inside your loop. Here the entire functioning program
EDIT 2: Okay here's the outer $(document).ready() wrapper also that isn't even in the original question. This has been tested. this works. Even on 1.3+ .. It's the best answer given.
I've put up a functioning version of this program you can try out by visiting here
$(function() {
for (n = 0; n < 20; n++){
$('#button' + n).bind('click', n, function (e) { newAction(e.data); });
}
});
function newAction(x){
alert(x);
}