javascript - How to stop an event callback firing itself? -


i wrote javascript event listener trap clicks on capture phase, perform action, repeat click trigger whatever code should happen.

var obj=document.getelementbyid('button'); obj.addeventlistener('click', function(event){     event.stoppropagation();     console.log('performing operation here');     otheroperation('ajax', function(){         obj.click();     }); }, true); 

obviously creates infinite loop of operations. thought best approach because operation requires time delay , can't continue event propagation until callback.

is there way detect click performed own callback function , therefore ignore it?

i had theory remove event listener after operation complete, need added again in circumstances makes lot of code.

a hacky solution workn on of browsers copy button itself, hide or remove original one, add click handler new one, , call button.click() on old 1 when neccessary.


Comments