Excluding form elements on keypress
I have a keypress assigned to a div, for example pressing A will show the div, press again to hide, problem is this also happens in form elements,开发者_开发知识库 have looked at other questions and answers but none worked for me.
I'm using:
$(document).keypress(function(ev) {
if (ev.which === 65 || ev.which === 97) { // 'A' or 'a'
$('#mainMenu').toggle();
}
});
How can I exclude textfields from this?
check the ev.target
something like:
if ($(ev.target).is(":input")) {
return;
}
精彩评论