When user clicks some button on my MVC view, I want to simulate the event that gets executed on Escape key. How can I achieve it using JQuery?
function pressEsc() {
$('body').trigger({
type: 'keyup',
which: 27 // Escape key
});
}
$(function () {
$('body').on('keyup', function (e) {
alert(e.which + ' key was pressed');
});
// Press the escape key
pressEsc();
});
Demo : http://jsfiddle.net/T4H89/