Sometimes, we want to remove focus from submit button with JavaScript
In this article, we’ll look at how to remove focus from submit button with JavaScript.
How to remove focus from submit button with JavaScript?
To remove focus from submit button with JavaScript, we can call the button’s blur
method.
For instance, we write:
<form>
<input type="submit">
</form>
to add a form.
Then we write:
const form = document.querySelector('form')
const submit = document.querySelector('input[type="submit"]')
form.onready = () => {
submit.blur()
}
We select the form and the submit button with querySelector
.
Then we call submit.blur
when the form is loaded by setting form.onready
to a function that calls blur
.
Conclusion
To remove focus from submit button with JavaScript, we can call the button’s blur
method.