$(document).keypress(function(e)
{
alert(e.keyCode);
if(e.keyCode==27)
{
hide_menu();
}
});
I get the alert for all keys except the escape key and the success part of the if
is never getting called. Why this happens?
$(document).keypress(function(e)
{
alert(e.keyCode);
if(e.keyCode==27)
{
hide_menu();
}
});
I get the alert for all keys except the escape key and the success part of the if
is never getting called. Why this happens?
use $(document).keyup instead of $(document).keypress
the following code works fine:
$(document).keyup(function(e)
{
alert(e.keyCode);
if(e.keyCode==27)
{
alert ("Esc key");
hide_menu();
}
});
You can change the keypress
to keyup
(better to use keyup) or keydown
:
$(document).keyup(function(e){
alert(e.keyCode);
if(e.keyCode==27){
hide_menu();
}
});