yeowoh
yeowoh

Reputation: 143

Hiding in the iOS keyboard when user clicks outside of a text box

I'm attempting to hide the iPad soft keyboard when the user clicks outside a text field.

Specifically somewhere on the form or body that contains no other elements.

Using jquery, jquery mobile, and html5.

Upvotes: 10

Views: 8919

Answers (3)

clintgh
clintgh

Reputation: 2077

using mattwindwer's solution (but with more details):

$(document).click(function() {
    document.activeElement.blur();
});

Upvotes: 3

mattwindwer
mattwindwer

Reputation: 929

document.activeElement.blur();

Upvotes: 11

Tejesh Alimilli
Tejesh Alimilli

Reputation: 1800

Calling focus() method on a button (even hidden buttons) hides the keyboard. I have used this in my ipad web app.

You can add a click listener to body and using target property of the event, you can determine when to hide the keyboard.

Upvotes: 1

Related Questions