javascript remove event listener – How to remove a DOM event listener using Javascript?

javascript remove event listener – Use the removeEventListener() Method to Remove Event Listener in JavaScript

javascript remove event listener | Remove an Event Handler

The removeEventListener() method is used to remove an event listener which were attached by addEventListener() method.

var element_name = document.querySelector('#btn');
var flag = 0;
var counter = function(event) {
    flag++; 

    if(flag == 2){ 
        this.removeEventListener('click', someEventHander);
    } 
}
element_name.addEventListener('click', counter);

javascript remove event listener

var myHandler=function(event){
	console.log("do something");
}

//add listener
document.getElementById("someid").addEventListener('click',myHandler);

//remove listener 
document.getElementById("someid").removeEventListener('click',myHandler);

How to remove a DOM event listener using Javascript?


   

  
  
    

String Reverser

Output

JavaScript Event Listeners

index.html




   
    JavaScript Event Listner - www.pakainfo.com
 


  
 




Don’t Miss : JQuery Disable OnClick Event Listeners

Remove Event Listeners




   
    JavaScript remove Event Listner - www.pakainfo.com
 



 





I hope you get an idea about javascript remove event listener.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment