Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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