removeEventListener CODE
First we add
click
event listener for two functions:
func1
,
func2
to document object. After clicking three times we remove the event listener for
func1
function
let counter = 0;
document.addEventListener('click', func1);
document.addEventListener('click', func2);

function func1(){
    console.log('You clicked me!');
  
    if (counter>2) {
        console.log('Max limit is 3');
        document.removeEventListener('click', func1);
    }
}
function func2(){
    counter ++;
    console.log('counter: '+counter);
}
by Valeri Tandilashvili
4 years ago
JavaScript
Events
1
Pro tip: use ```triple backticks around text``` to write in code fences