-2

I would like the keyPress == 13 function to occur when a button has been clicked. Is this possible in Jquery?

Reason why I'm trying to figure this out is because im using a plugin which redirects a search term to an allocated page when pressing the enter key, but this does not work when I click the submit button. So I was wondering If I could mimic the enter key when button has been click.

Also I apologise for my terminology as I'm a beginner. Thanks.

Sonny
  • 11
  • 1
  • See the duplicates for more information. Also note that faking key events in the DOM isn't a good idea, and can be flaky depending on the end result you want to achieve. It's a much better idea to separate the required logic into a function and call that directly. – Rory McCrossan Jan 14 '19 at 08:41

1 Answers1

0

try this.

var e = $.Event( "keypress", { which: 13 } );
$('#yourInput').trigger(e);
Asim Khan
  • 1,969
  • 12
  • 21