How to force the soft keyboard to hide with JavaScript?

Estimated read time 1 min read

You can force the soft keyboard to hide in JavaScript by programmatically setting the focus to a different element on the page. Here’s an example:


In this example, we use the document.getElementById method to get a reference to a form input element with an ID of “input”. We then call the blur method on this element, which removes focus from the element and closes the soft keyboard.

Note that this method only works on mobile devices, where the soft keyboard is displayed when an input field has focus. On desktop devices, there is no soft keyboard to hide.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply