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.
HTMLElement.blur()
メソッドは、現在の要素からキーボードフォーカスを取り除きます。
構文
js
blur()
引数
なし。
返値
なし (undefined
)。
例
テキスト入力からフォーカスを取り除く
HTML
html
<input type="text" id="sampleText" value="サンプルテキスト" /><br /><br />
<button type="button" onclick="focusInput()">
クリックするとフォーカスを得ます
</button>
JavaScript
js
function focusInput() {
const textField = document.getElementById("sampleText");
textField.focus();
// 入力欄から 3 秒後にフォーカスが外れる
setTimeout(() => {
textField.blur();
}, 3000);
}
結果
仕様書
Specification |
---|
HTML # dom-blur-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
blur |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.