Just a quick question, I seem to do this a lot:
$saveBtn.bind("click keypress", function(e)
{
if (e.type != "keypress" || e.keyCode == 13)
{
// Do something...
return false;
}
});
Is there a quicker way to bind an ‘action’ listener to a button? I want to always ensure my buttons with event listeners fire on both clicks and the enter key…this seems like it’d be a fairly common thing to want to do but found nothing on google. Any thoughts?
Thanks.
By binding it with
clickwill do the job, no need for keep press. Example