O método HTMLElement.blur()
remove o foco do teclado no elemento corrente.
Sintaxe
elemento.blur();
Exemplos
Removendo o foco de um input de texto
HTML
<input type="text" id="meuTexto" value="Texto Exemplo">
<br><br>
<button type="button" onclick="focusInput()">Clique para definir o foco</button>
<button type="button" onclick="blurInput()">Clique para remover o foco</button>
JavaScript
function focusInput() {
document.getElementById('meuTexto').focus();
}
function blurInput() {
document.getElementById('meuTexto').blur();
}
Resultado
Especificação
Especificação | Status | Comentário |
---|---|---|
HTML Living Standard The definition of 'blur' in that specification. |
Padrão em tempo real | |
HTML 5.1 The definition of 'blur' in that specification. |
Recomendação | |
HTML5 The definition of 'blur' in that specification. |
Recomendação | |
Document Object Model (DOM) Level 2 HTML Specification The definition of 'blur' in that specification. |
Obsoleto |
Compatibilidade com navegadores
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Veja também
- Método DOM
HTMLElement.focus()