LoginSignup
1
0

More than 3 years have passed since last update.

[JavaScript]focusを外す方法

Last updated at Posted at 2020-12-09

はじめに

focusとは?

例として↓の画像のようにキーワードが入力出来るようになっている事をフォーカスが当たっていると表現するらしい。

一部のAndroidでは、このような検索画面があった場合に検索後もキーボード入力画面が残り、操作しにくい状況となることがある。(※qiitaでは症状は現れない。きっと処理を書いてる)

この記事では、そのフォーカスを解除する方法を備忘録として記事にまとめる。

iOS の画像 (41).jpg

focusされている部分のfocusを解除する方法

まずJavascriptではfocusを解除するにはblue関数を使用する

要素.blue()

次に現在アクティブな要素を取得する方法

document.activeElement

この2点から下記のように書くとfocusを外す事ができる

document.activeElement

参考

・activeElement
 ・https://developer.mozilla.org/ja/docs/Web/API/Document/activeElement
・blur
 ・https://developer.mozilla.org/ja/docs/Web/API/HTMLOrForeignElement/blur
・focus
 ・https://developer.mozilla.org/ja/docs/Web/API/HTMLOrForeignElement/focus

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0