JSFiddle - React, Tailwind, and code Playground
HTML
<p>You will receive an alert with the text "submitted" on clicking the submit button or hitting the enter key while in the input box.</p>
<input id="input" type="text" /><button id="button">Submit</button>
JavaScript
(function ($) {
$.prototype.enterPressed = function (fn) {
$(this).keyup(function(e) {
if ((e.keyCode || e.which) == 13) {
fn();
}
});
};
}(jQuery || {}));
function submitted() {
alert('submitted');
}
$("#input").enterPressed(submitted);
$("#button").click(submitted);