Reputation: 668
Can't think of how to do this, I wan't a div element to unhide itself when the user presses a key on the keyboard, like instead of hovering a button or something.
Is this possible? thinking jquery?
Upvotes: 1
Views: 376
Reputation: 339816
$(document).keypress(function(ev) {
if (ev.which === 65 || ev.which === 97) { // 'A' or 'a'
$('#mydiv').toggle();
}
});
See http://jsfiddle.net/alnitak/R4rWn/
If you wanted to capture a control key (ctrl, alt, caps-lock, etc) then you have to use .keydown()
instead.
Upvotes: 7