So I want to call a function and pass it parameters on a click event using vanilla javascript (which I've done) but I'm having a problem with detaching the event afterward. When the click event is fired I want to call a function and pass it parameters including the event object and then detach the event. I've tried a few things but the problem I'm running into is that the anonymous function can't be referenced after calling it so I can't pass it as a parameter to the event "unhandler". How can I capture the touch event while also passing parameters the the callback?
function bindClickExpandEvent(element, type, handler, obj) {
if (element.addEventListener) {
element.addEventListener(type, function (event) {
handler(event, obj);
}, false);
} else {
element.attachEvent('on' + type, function (event) {
handler(event, obj);
});
}
}
function removeClickExpandEvent(elem, eventType, handler) {
if (elem.removeEventListener)
elem.removeEventListener(eventType, handler);
if (elem.detachEvent)
elem.detachEvent('on' + eventType, handler);
}