Definitive way to trigger keypress events with jQuery

mkoryak picture mkoryak · May 7, 2009 · Viewed 281.9k times · Source

I've read all the answers on to this questions and none of the solutions seem to work.

Also, I am getting the vibe that triggering keypress with special characters does not work at all. Can someone verify who has done this?

Answer

Nadia Alramli picture Nadia Alramli · May 7, 2009

If you want to trigger the keypress or keydown event then all you have to do is:

var e = jQuery.Event("keydown");
e.which = 50; // # Some key code value
$("input").trigger(e);