user475685
user475685

Reputation: 8329

how to trigger a button in html on pressing the Enter key

I have a UI with a button, i want the button to take the click on pressing the Enter key?

Upvotes: 1

Views: 960

Answers (1)

Mukesh
Mukesh

Reputation: 807

if(event.which || event.keyCode) {
  if ((event.which == 13) || (event.keyCode == 13)) {
    document.getElementById('buttonID').click();
    return false;
  }
}
else {
  return true;
}

Upvotes: 4

Related Questions