Last active
November 22, 2016 03:11
-
-
Save mattConn/1db57d43685476a9378b144175d617b7 to your computer and use it in GitHub Desktop.
JQuery switch statement for key binding.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).keyup(function(e) { //keydown can be used as well. | |
switch(e.which) { | |
case 37: //left; any keycode can be used for each case. | |
alert('keycode: '+e.which); | |
break; | |
default: return; // exit this handler for other keys | |
} | |
e.preventDefault(); // prevent the default action (scroll / move caret) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo/test:
http://codepen.io/mattConn/pen/aBJRLw?editors=1010