During a recent project, a requirement came up for hiding the iOS keyboard when a user tapped the “Done” or “Go” button on the keyboard while they were filling out a web form. We did a bit of research and came up short on a solution that fit our needs.

Others with similar requirements recommended taking the focus off all the inputs on the screen, which in turn hid the keyboard. We took that approach and listened for a keyup event for the final solution. Here’s what we came up with using jQuery:

$(document).on("keyup", "input", function(event) {
    // If enter is pressed then hide keyboard.
    if(event.keyCode == 13) {
        $("input").blur();
    }
});

The solution ended up being pretty simple, but we thought we’d share the solution in case anyone else had a similar requirement.