Last active
September 1, 2016 15:51
-
-
Save YurePereira/1092371c3f8550db8d777b73389038f4 to your computer and use it in GitHub Desktop.
Capturing enter key in jQuery
This file contains hidden or 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
| //With ternary operator: | |
| $(document).keypress(function(e){ | |
| var keycode = e.keyCode ? e.keyCode : e.which; | |
| if(keycode === 13){ | |
| //Code action here. | |
| } | |
| }); | |
| //Or with bitwise: | |
| $(document).keypress(function(e) { | |
| var keycode = e.keyCode || e.which; | |
| if(keycode === 13) { | |
| //Code action here. | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment