Search code examples
javascriptjqueryeventstriggerskeypress

Definitive way to trigger keypress events with jQuery


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?


Solution

  • 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);