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

190
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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