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

225
Views
How Can I stop ParentNode from getting called recursively everytime I trigger the event listener?

I have this check button to remove elements from the list, and whenever I press an element from the bottom of the lists it removes the whole thing, I've tried using break but it keeps executing.

This is what the code looks like:

let checkBtns = document.getElementsByClassName('checkbox-round');
      for (let i = 0; i < checkBtns.length; i++) {
        checkBtns[i].addEventListener('click', () => {
          console.log(`executing for ${i}`);
          checkBtns[i].parentNode.remove();
          tasks.splice(i, 1);
          break;
        });
      }

And here's a screenshot of the behavior in console:

enter image description here

  • The underlined log is the normal expected behavior when I delete a node that's on top of the list
  • The log under is for when I delete a node on the bottom that recursively calls itself
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As @aerial mentioned replacing getElementsByClassName with querySelectorAll solved the issue

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!