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

194
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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