1. ホーム
  2. ジャバスクリプト

[解決済み] [Solved] Is it possible to focus on a <div> using JavaScript focus() function?

2022-04-02 13:39:16

Question

Is it possible to focus on a <div> using JavaScript focus() function?

I have a <div> tag

<div id="tries">You have 3 tries left</div>

I am trying to focus on the above <div> using :

document.getElementById('tries').focus();

But it doesn't work. Could someone suggest something....?

How to solved?

window.location.hash = '#tries';

これは該当する要素までスクロールし、実質的に "フォーカス"されます。