This question is not about fixing a code,as I managed to do it, but to understand why it's happening.
The idea was to delay a pop-up window (with 2 buttons and 1 input text). Initially I used version-b(a setTimout function using an arrow function as a parameter) but buttons weren't responding to any interaction. After trying different things I tried extracting the arrow function, in version-b, into a regular function (version-a) and everything worked perfectly. I guess the issue is related to the way setTimeout() and arrow functions work but couldn't find the reason why it's happening.
VERSION-A:
let usrNameQs="";
function loadPopUp(){
setTimeout(()=>{
document.querySelector(".popup").style.display = "block";
usrNameQs=document.querySelector("#userName");
usrNameQs.value="";
changeNamePlayer("");
},500);
}
window.addEventListener("load",loadPopUp());
VERSION-B:
let usrNameQs="";
window.addEventListener("load",**setTimeout(()=>**{
document.querySelector(".popup").style.display = "block";
usrNameQs=document.querySelector("#userName");
usrNameQs.value="";
changeNamePlayer("");
},500)
);