You can bind () for several events:
$(button).bind("click keydown", function (evt) {
if (evt.type == "keydown" && evt.which == 39)
alert("Key 39 pressed");
else if (evt.type == "click")
alert("Clicked!");
});
Example: http://jsfiddle.net/Bymug/
Note that the space and enter keys can also trigger a click event on a button.
source
share