Answer the question
In order to leave comments, you need to log in
How to find out which hidden HTML element has focus?
Dear Gurus please give me some advice.
I am making a website. I click Tab. I watch the focus move. At some point, the focus is NOT visible, and it is not clear where it is. How to find out at what current moment the HTML element is selected with focus?
Answer the question
In order to leave comments, you need to log in
Usually manually searching for a focused element does not work, because when you open the developer console, the focus on the element flies. If you focus it again with the console open, the focus flies at the moment when you switch to an already open console. So, the most suitable option: you can listen to focus events and immediately print to the log who received this focus. This code should help:
window.addEventListener('focusin', event => console.log(new Date, event.target));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question