Home > Back-end >  JS on page load debug
JS on page load debug

Time:04-15

A form field with the ID of mainSearch gets focus when the page loads. I am struggling to debug this and find out where that gets set in the source code. Is there a way I can debug this element to see how it is getting focus?

CodePudding user response:

There are several ways to make element autofocused.

  1. HTML only: Just place autofocus attribute.
  2. JS: Use element.focus().

So, if I were you, I'll search for .focus() in sources. Then, make several break points nearby.

CodePudding user response:

Maybe it is because of :focus-visible pseudo-class applies while an element matches the :focus . i also suffered many time with this,then I try

*:focus-visible{
 outline:none!important;
/* your style */
}

CodePudding user response:

try this

console.log(getEventListeners(document.getElementById("mainSearch")));
  • Related