How can I not remove, and stop the event handler addEventListener if we assume there is js code:

 var count = 0; el.addEventListener('click', function but(){ console.log(count); if (count >10) removeEventListener('click',but); count++; }, false) 

it turns out that at the 11th clique the event will not take place. And if this same count is dumped somewhere, then the same event will no longer work. Maybe you need to return false or something I do not understand? I would like that the 4th line would not delete the event, namely, it would not allow the event function to work, which would further allow using it again. I apologize in advance for the abstraction

  • 3
    Well, check the condition at the very beginning of the method, and if it is suitable, make return - Grundy
  • would there be an undefined error on count? - ddeadlink
  • one
    And the fact that you have this count is always == 1 and the condition is never fulfilled so it is intended? This is a question for you actually, whether there will be errors undefined - Darth
  • Sorry, fixed - ddeadlink
  • for the current code - will not be :) - Grundy

0