Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
element.addEventListener fires multiple times

I tried debugging the only thing i found was everytime parent function executes more event listeners being added :(

I think line 46-69 has the problem. Here is the codepen link:

https://codepen.io/disaladamsas/pen/NWvXNGd?editors=0011

const cancelDeletion = (element) => {
  toggleBackdrop();
  deleteModalConfirmation.classList.remove("visible");
};
const confirmDeletion = (element) => {
  toggleBackdrop();
  element.remove();
  deleteModalConfirmation.classList.remove("visible");
};

const deleteMovieModal = (element) => {
  toggleBackdrop();
  deleteModalConfirmation.classList.add("visible");
  cancelDeletionElement.addEventListener(
    "click",
    cancelDeletion.bind(this, element)
  );
  confirmDeletionElement.addEventListener(
    "click",
    confirmDeletion.bind(this, element)
  );
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This might be because everytime deleteMovieModal runs, you register a new event listener, so when it runs the first time you add one event listener, and when it runs the second time you have two event listeners, etc.

Either remove them with removeEventListener or use addEventListener('something', someCallback, { once: true })

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!