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

146
Vistas
Why does the if statement ignore the expression while removing DOM nodes?

I've tried all sorts of solutions to index a array and remove elements that match a regex. The solution I ended up with should work, as it doesn't skip loop iterations due to the array length changing, which is the problem I had before. However now it just seems to ignore my if statement.

   const iframes = Array.from(document.getElementsByTagName("iframe")).filter(frame => frame.getAttribute("src") == "/domain/to/iframe");
   const idoc = iframes.length === 1 ? iframes[0].contentWindow.document : document;
   const regex = /.*TextGoesHere*/sig;
   var msgs = idoc.getElementsByClassName("message");
   msgs = Array.from(msgs);
   while (msgs.length > 0) {
    removal = msgs.pop(msgs.length);
    if (regex.test(removal.innerHTML)) {
        removal.remove();
    } else {
        console.log(regex.test(removal.innerHTML));
    }
   }

Output:

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