What would be the best option to get the same functionality as ".toggle" for a ".keydown" event?
What I'm trying to do is display a menu on keydown, having it go away when the key is pressed again. Specifically I'm using the "M" key. Here's my code so far:
- $(document).ready(function() {
- $('#menu').hide();
- $(document).keydown(function(e) {
- if (e.which == 77) {
- $('#menu').toggle(function() {
- $('#menu').fadeIn('fast');
- },function(){
- $('#menu').fadeOut('fast');
- }
- }
- });
- $('#navNotification').click(function() {
- $('#navNotification').fadeOut('slow', function() {
- });
- });
- });
The highlighted section is what I want. I already know that this won't work, because I've tried it then re-read the description and realized that ".toggle" binds to the click function. That's fine, but I need the same functionality on a ".keydown" event. Any suggestions?