Skip to content Skip to sidebar Skip to footer

I Want To Press Enter Key By Programmatically When User Do Some Stuff In Js

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

Solution 1:

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.

Post a Comment for "I Want To Press Enter Key By Programmatically When User Do Some Stuff In Js"