Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140273

remove event listener with parameters

$
0
0

I am trying to remove some listeners attached to certain array of elements.

As I am adding the event listeners I cannot get a reference to the parameters I needs. I have been doing some research and found out that can be solved using closures, but I can't figure out very well how to do it

here is my function reference

const editTask = function (element, taskIndex) {
   const handler = function(event) {
   // my code ...
   }
}

and this is how I am adding the listeners

function addEditListeners() {
  const editButtons = [].slice.call(document.getElementsByClassName("edit-btn"));
  console.log('editbuttons', editButtons);
  //editButtons.forEach(function (element) {
  //    element.removeEventListeners("click", editTask);
  //});
  editButtons.forEach(function (element, index) {
    element.addEventListener("click", handler);
  });
}

I have tried sending the parameters in parenthesis but the editTask is undefined, what am I doing wrong?


Viewing all articles
Browse latest Browse all 140273

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>