Refactoring question

Refactoring question

New to jQuery, but not to programming JS. There has to be a cleaner way to do all this:
$("#guest1pay").click(function () {
   addamounts(1);
});
$("#guest2pay").click(function () {
   addamounts(2);
});
$("#guest3pay").click(function () {
   addamounts(3);
});
$("#guest4pay").click(function () {
   addamounts(4);
});

function addamounts(num) {
   ...do_something
}

Is this something for
.each
?
Thanks.
    • Topic Participants

    • bradc