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.
- HTML only: Just place
autofocus
attribute. - 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")));