Event listeners remain active until you remove them from the associated JavaScript elements. You can use the following syntax to do so.
element.removeEventListener(type, listener, useCapture);
Event listener removal parameters are similar to ones you use to add event listeners. When you remove an event listener, you must specify the same type, listener, and useCapture parameters. If you don’t, the event listener will remain active and keep triggering for future events.
For example, you can add an event with the following code.
button.addEventListener("click", RespondMouseClick, true);
But applying the following code fails to remove the event listener. That’s because the useCapture value differs from the one registered with the button object.
button.removeEventListener("click", RespondMouseClick, false);
To successfully remove the event and prevent it from being triggered, you can use the following code.
button.removeEventListener("click", RespondMouseClick, true);