Skip to content

Instantly share code, notes, and snippets.

@goliatone
Created November 22, 2013 04:09
Show Gist options
  • Save goliatone/7594727 to your computer and use it in GitHub Desktop.
Save goliatone/7594727 to your computer and use it in GitHub Desktop.
keydown wrapper
(function($) {
$.fn.enterKey = function(key, handler) {
return this.keydown(function(ev) {
if (ev.which == key)
return handler.call(this, ev);
});
};
})(jQuery);
$('#test').enterKey(13, function(ev) {
console.log(ev)
alert('You hit enter after typing: ' + this.value);
});
//<input id=test value="Hit enter in this textbox" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment