Skip to content
Advertisement

Remove eventlistener

Help:-) How do i remove this listener?

JavaScript

_handlePlay looks like this:

JavaScript

i tried…

JavaScript

and more desperately:

JavaScript

but the listener wont leave the scene?

I have the bind as I am in js and web component context

/regards

Advertisement

Answer

The function you pass to removeEventListener needs to be the same function that you pass to addEventListener.

bind creates a new function.

JavaScript

Since you don’t keep the value of this._handlePlay.bind(this), there’s no way to get that function back to pass it to removeEventListener.


You need to keep the value somewhere that you can access when you later try to remove the event listener.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement