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

141
Views
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
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!