Created
November 4, 2011 22:03
-
-
Save DaveSanders/1340607 to your computer and use it in GitHub Desktop.
JQuery add-on that adds a "enter" key press event
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
jQuery.fn.enter = function(callback) { | |
this.keypress(function(e){ | |
if (e.which == 13) { | |
e.preventDefault(); | |
callback.call(this); | |
} | |
}); | |
return this; | |
} | |
usage: | |
$("#myInput").enter(function(){alert('this is my callback');}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment