0

I cannot get this removeEventListener to function!

I'm wondering if it has something to do with needing to pass an item into the function that is called.

when I build the eventlistner i am using:

window.dummyElement = document.getElementById('dummyElement ')
dummyElement.addEventListener('click', submitNewAction.bind(event, item), true)

This is the removeEventListner Im using:

dummyElement.removeEventListener('click', submitNewAction.bind(event, item), true)

I have also tried:

dummyElement.removeEventListener('click', submitNewAction, true)

and

dummyElement.removeEventListener('click', submitNewAction(), true)

I'm Stumped as to why this isn't working... any ideas?

  • 1
    Save `submitNewAction.bind(event, item)` to a variable and then pass that into the `removeEventListener` – evolutionxbox Apr 06 '21 at 11:08
  • 2
    You need to use the reference to the _exact_ same function instance in removeEventListener, that was used with addEventListener in the first place. `submitNewAction.bind` creates a _new_ function each time, calling this twice will _not_ get you the same one. – CBroe Apr 06 '21 at 11:09
  • Does this answer your question? [Javascript removeEventListener not working](https://stackoverflow.com/questions/10444077/javascript-removeeventlistener-not-working) – user3840170 Apr 06 '21 at 11:17

0 Answers0