-2

When I use the following "jquery.event" line:

var newevent= jQuery.Event("keypress").which(40).keycode(40);

...I get the following error:

Uncaught TypeError: jQuery.Event(...).which is not a function

How can I prevent this error?

Further clarification:

When the two lines I use are:

  var newevent= jQuery.Event("keypress").which(40).keycode(40);
  $('#juris1 .selectpicker').trigger(newevent);

This code triggers the event (and opens a select box), but I get the error.

When I use the standard way from the API documentation, I no longer get an error, but the code does not trigger the keypress

var newevent = jQuery.Event("keypress", { keyCode: 40, which: 40 });
user749798
  • 5,210
  • 10
  • 51
  • 85

1 Answers1

0

Per the documentation... https://api.jquery.com/category/events/event-object/

var newevent = jQuery.Event( "keypress", { keyCode: 40 } );

Per this post Definitive way to trigger keypress events with jQuery

var newevent = jQuery.Event("keypress");
newevent.keyCode = newevent.which = 40; // # Some key code value
$('#juris1 .selectpicker').trigger(newevent);
hawkstrider
  • 4,141
  • 16
  • 27