0

I have a DOM element in my frame, and when I click on it, I want to simulate a ESCAPE key press (so I cannot use keydown or keyup, because its the click that generates it)

Is it possible?

  • 1
    Follow link :)... http://stackoverflow.com/questions/596481/simulate-javascript-key-events – Chris Jun 19 '12 at 10:48
  • What exactly are you trying to accomplish? What should receive and react to that `esc` keypress? – lanzz Jun 19 '12 at 10:49

2 Answers2

1

With jQuery:

e = jQuery.Event("keydown"); 
e.which = 27; //27 = ESC
$("youelement").trigger(e);
Barrie Reader
  • 10,647
  • 11
  • 71
  • 139
0

If I'm not mistaken, the jquery trigger can be used with jQuery.Event object with type as keypress

JSantos
  • 1,698
  • 22
  • 39