Skip to content

Instantly share code, notes, and snippets.

@DaveSanders
Created November 4, 2011 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveSanders/1340607 to your computer and use it in GitHub Desktop.
Save DaveSanders/1340607 to your computer and use it in GitHub Desktop.
JQuery add-on that adds a "enter" key press event
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