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

119
Views
How to prevents events from firing multiple time

For some reason I have to call the same function twice because of that my event are firing twice. How can I prevent this?

function renderSeats(movieImg, title, release_date, dummyPrice = '3000') {
     
      // selected items
       //this is only a part of the code . 
      contianer.addEventListener('click', function (e) {
        if (
          e.target.classList.contains('seat') &&
          !e.target.classList.contains('unavailable')
        ) {
          e.target.classList.toggle('selected');
          payoutBtn.classList.add('active');
          console.log('yes');
          updateCountTotal(); //function call
        }
        contianer.setAttribute('listener', 'true');
      });
    
      const ticketOverlayClose = document.querySelector('.ticket__close-svg');
      // overlay deactive
      ticketOverlayClose.addEventListener('click', function (e) {
        overlayseats.classList.add('hidden');
        payoutBtn.classList.add('active');
        ticketContainer.classList.remove('active');
      });
    }

Every time I am calling the function from another function because I have to update the dom, suppose 3 times the event then also fire 3 times

I also attached an image. In the console, you see after I clicking back (it is a single-page app) and again load by page calling our rendered seat function, and this time when I click on the seats the even is firing twice.

[gif][1]:https://i.stack.imgur.com/Ik1CG.gif

about 4 years ago · Juan Pablo Isaza
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!