I have difficulties with event listeners and unbinding them. I have the following code:
function delegate(el, evt, sel, handler) {
el.addEventListener(evt, function(event) {
var t = event.target;
while (t && t !== this) {
if (t.matches(sel)) {
handler.call(t, event);
}
t = t.parentNode;
}
});
}
And I apply the function like this:
function captureMouseDown() {
console.log('mouse downed');
}
delegate(document, 'mousedown', '.js-flex', captureMouseDown);
How do I undelegate the event on the document and/or the selector js-flex