Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
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 Respuestas
Responde la pregunta

0

As @aerial mentioned replacing getElementsByClassName with querySelectorAll solved the issue

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda