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

182
Views
if (element.textContent.trim() === 'Tea') Does not exist?

I'm playing around with some code and I'm almost there but i can't figure out this one last thing.

I'm using document.getElementsBy to look for a word in an Iframe, and it works. But when it finds the word it goes on to another Function.

I want it to send an Alert("not found") if it does not find the word.

function myFunction2() {
  var iframe2 = document.getElementById("myFrame");
  const allElements = iframe2.contentWindow.document.getElementsByTagName("li");
  for (const element of allElements) {
    console.log(element);
    if (element.textContent.trim() === 'Tea') {
      alert(element.textContent.trim());
    }
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could just store whether you found 'Tea' in a boolean.

That would look something like this:

function myFunction2() {
  var iframe2 = document.getElementById("myFrame");
  const allElements = iframe2.contentWindow.document.getElementsByTagName("li");
  let foundTea
  for (const element of allElements) {
    if (element.textContent.trim() === 'Tea') {
        found = true
      alert('Tea');
    }
  }
  if (!foundTea) {alert('Not found')}
}
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!