-8

Is there any way to simulate an enter key press in JavaScript when the user does some stuff?

Cœur
  • 34,719
  • 24
  • 185
  • 251
pampa vandli
  • 1
  • 1
  • 3

1 Answers1

0

You can use:

var e = jQuery.Event("keypress");
e.which = 13; //enter keycode
e.keyCode = 13;
$("#theInputToTest").trigger(e);

The trigger function simulate an event (for example a click, a key pressed...).

More information here

Description: Execute all handlers and behaviors attached to the matched elements for the given event type.

There is a question like yours with answers here.

Albert Lázaro de Lara
  • 2,363
  • 5
  • 25
  • 36