I want to create javascript function adds an event listener to a div such that when the div is clicked, it runs a function, and ensures that the div can only be clicked once. My function looks like this right now:
function clickOnce(divID,func){
var args = Array.prototype.slice.call(arguments,2);
functionToRun=partial(func,args);
thisDiv=document.getElementById(divID);
thisDiv.addEventListener("click",function(e){
e.target.removeEventListener(e.type, arguments.callee);
functionToRun();
});
}
I have a working example in jsfiddle: https://jsfiddle.net/qtzLhgr4/1/ In the JSfiddle, when I click button 1 it says "button #2 clicked".