Is there anyway to remove an event listener added like this:
element.addEventListener(event, function(){/* do work here */}, false);
without replacing the element?
Is there anyway to remove an event listener added like this:
element.addEventListener(event, function(){/* do work here */}, false);
without replacing the element?
Assigning event handlers with literal functions is tricky- not only is there no way to remove them, without cloning the node and replacing it with the clone- you also can inadvertantly assign the same handler multiple times, which can't happen if you use a reference to a handler. Two functions are always treated as two different objects, even if they are character identical.
You could remove the event listener like this:
element.addEventListener("click", function() {
element.removeEventListener("click", arguments.callee, false);
}, false);
There is no way to cleanly remove an event handler unless you stored a reference to the event handler at creation.