I want to be able to set the addEventListener to un-attach after the first event, based on a conditional related to the event.
I want something like;
var thing = document.querySelector('.thing');
thing.addEventListener('click',function(e){
if (e.pointerType === 'mouse'){
this.addEventListener.options.once = true;
}
});
<a class="thing">Thing</a>
You want to use removeEventListener. You can do it like this:
function handler(event){
if (event.pointerType === 'mouse'){
this.addEventListener.options.once = true;
var targetElement = event.target || event.srcElement
targetElement.removeEventListener("click", handler);
}
}
var thing = document.querySelector('.thing');
thing.addEventListener('click',handler);