user1145064
user1145064

Reputation:

Make a key be pressed with javascript

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?

Upvotes: 0

Views: 807

Answers (2)

JSantos
JSantos

Reputation: 1708

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

Upvotes: 0

Barrie Reader
Barrie Reader

Reputation: 10715

With jQuery:

e = jQuery.Event("keydown"); 
e.which = 27; //27 = ESC
$("youelement").trigger(e);

Upvotes: 1

Related Questions