フォーカスされているか調べる focus blur
<button>”1”</button>
<button>”2”</button>
<button>”3”</button>const btns = document.querySelectorAll("button");
btns[2].focus(); // フォーカスをあてる
btns.forEach((b) => {
b.addEventListener("focus", (e) => {
console.log(e.target.textContent + "がフォーカスされました。");
});
});
btns.forEach((b) => {
b.addEventListener("blur", (e) => {
console.log(e.target.textContent + "からフォーカスが外れました。");
});
});