blur method

The blur method removes focus from an element.

Syntax

javascriptelement.blur();

Example

Let's click on one button to set focus on the input, and on click on another - remove it:

html<input value="text" id="input">
<input type="button" value="focus" id="focus">
<input type="button" value="blur"  id="blur">
javascriptlet 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 focus method
    that sets focus on an element