I write the following code all the time to handle when the enter key pressed:
$("#selectorid").keypress(function (e) {
if (e.keyCode == 13) {
var targetType = e.originalTarget ? e.originalTarget.type.toLowerCase() : e.srcElement.tagName.toLowerCase();
if (targetType != "textarea") {
e.preventDefault();
e.stopPropagation();
// code to handler enter key pressed
}
}
});
Is there a way to extend jQuery so that I could just write:
$("#selectorid").enterKeyPress(fn);