1var someEventHander=function(event){
2 console.log("do something");
3}
4
5//add listener
6document.getElementById("someid").addEventListener('click',someEventHander);
7
8//remove listener
9document.getElementById("someid").removeEventListener('click',someEventHander);
1That is not possible without intercepting addEventListener calls and keep track of the listeners or use a library that allows such features unfortunately. It would have been if the listeners collection was accessible but the feature wasn't implemented.
2
3The closest thing you can do is to remove all listeners by cloning the element, which will not clone the listeners collection.
4
5Note: This will also remove listeners on element's children.
6
7var el = document.getElementById('el-id'),
8 elClone = el.cloneNode(true);
9
10el.parentNode.replaceChild(elClone, el);
1// type function
2element.removeEventListener("mousedown", handleMouseDown)
3// full type list available here: https://developer.mozilla.org/en-US/docs/Web/Events
1var someEventHander=function(){
2 console.log("do something");
3}
4var handlerCopy=someEventHandler.bind(var1,var2)
5//add listener
6document.getElementById("someid").addEventListener('click',handlerCopy,true);
7//remove listener
8document.getElementById("someid").removeEventListener('click',handlerCopy,true);
1target.removeEventListener(type, listener[, options]);
2target.removeEventListener(type, listener[, useCapture]);