Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda