function buttonClicked() {
alert("clicked");
}
button1.addEventListener('click', buttonClicked);
button2.addEventListener('click', buttonClicked);
Or, for IE8 (which doesn’t have support for addEventListener
:
button1.onclick = button2.onclick = buttonClicked;
Or, with jQuery:
$button1.click(buttonClicked);
$button2.click(buttonClicked);
solved how to do function if one of two buttons clicked in jquery? [duplicate]