Failed To Execute 'addeventlistener' On 'eventtarget'
I struggle with a javascript error, that I cannot get rid of: Uncaught TypeError: Failed to execute 'addEventListener' on 'EventTarget': The callback provided as parameter 2 is not
Solution 1:
The 2nd parameter of window.addEventListener
should be a function.
What you have boils down to:
window.addEventListener("load", setTimeout(function(){ /* stuff */}, 3000));
That setTimeout
is called the moment you call addEventListener
, and the return value of setTimeout
(The timeout id
) is passed to addEventListener
.
You need to wrap the setTimeout
in a function:
window.addEventListener("load", () =>setTimeout(function(){
/* stuff */
}, 3000));
Now, you're passing a function to addEventListener
that can be called on the load
event. That function will set a new timeout.
Post a Comment for "Failed To Execute 'addeventlistener' On 'eventtarget'"