-8

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
pampa vandli
  • 1
  • 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 Lazaro de Lara
  • 2,540
  • 6
  • 26
  • 41