HTMLElement.blur()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

La méthode HTMLElement.blur() retire le focus du clavier de l'élément courant.

Syntaxe

js
blur();

Exemples

Retirer le focus d'un champ texte

HTML

html
<input type="text" id="monTexte" value="Texte d'échantillon" /> <br /><br />
<button type="button" onclick="focusInput()">
  Cliquez ici pour obtenir le focus
</button>
<button type="button" onclick="blurInput()">
  Cliquez ici pour perdre le focus
</button>

JavaScript

js
function focusInput() {
  document.getElementById("monTexte").focus();
}
function blurInput() {
  document.getElementById("monTexte").blur();
}

Résultat

must be provided

Spécifications

Specification
HTML
# dom-blur-dev

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
blur

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi