blur method
The blur method removes
focus from an element.
Syntax
element.blur();
Example
Let's click on one button to set focus on the input, and on click on another - remove it:
<input value="text" id="input">
<input type="button" value="focus" id="focus">
<input type="button" value="blur" id="blur">
let input = document.querySelector('#input');
let focus = document.querySelector('#focus');
let blur = document.querySelector('#blur');
// By clicking on the focus button, we set the focus to the input:
focus.addEventListener('click', function() {
input.focus();
});
// By clicking on the blur button, we will remove focus from the input:
blur.addEventListener('click', function() {
input.blur();
});
:
See also
-
the
focusmethod
that sets focus on an element