このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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 2015年7月.

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

ブラウザーの互換性

関連情報