Reputation: 12317
In JavaScript, how can I create my own event that I can dispatch to another function. For example, I want to create Enter Key press event
so I may dispatch to another function that accepts Keyboard events.
Upvotes: 0
Views: 2900
Reputation: 710
From Is it possible to simulate key press events programmatically?
function simulateKeyPress(character) {
jQuery.event.trigger({ type : 'keypress', which : character.charCodeAt(0) });
}
$(function() {
$('body').keypress(function(e) {
alert(e.which);
});
simulateKeyPress("e");
});
Upvotes: 2