Sometimes, we want to unfocus a textbox with JavaScript.
In this article, we’ll look at how to unfocus a textbox with JavaScript.
How to unfocus a textbox with JavaScript?
To unfocus a textbox with JavaScript, we call the blur
method.
For instance, we write
document.activeElement.blur();
to get the currently focused element with document.activeElement
.
Then we call blur
to unfocus the element.
Conclusion
To unfocus a textbox with JavaScript, we call the blur
method.