JavaScript removeEventListener() method with examples

JavascriptWeb DevelopmentObject Oriented Programming

The JavaScript removeEventListener() method is used to remove an event listener from an element that has been previously attached with the addEventListener() method.

Following is the code for removeEventListener() method −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      font-size: 18px;
      font-weight: 500;
<h1>JavaScript removeEventListener() method</h1>
<div class="sample"></div>
<button class="Btn">CLICK HERE</button>
Click on the above button to print a number
<button class="Btn">Remove event Listener</button>
<h3>Click on the above button to remove the event listener of the first button</h3>
   let sampleEle = document.querySelector('.sample');
   let j=0;
   function printNum(){
      sampleEle.innerHTML += 'Number = ' + j++ + '<br>';
      sampleEle.innerHTML = 'Event listener has been removed';


The above code will produce the following output -

On clicking ‘CLICK HERE’ three times −

On clicking the ‘Remove event Listener’ button and clicking on the ‘CLICK HERE’ button again −

Updated on 11-May-2020 14:39:33