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

216
Vistas
getElementsByTagName() and text inside .click

I have clickable list elements, same class and role, and just text inside is different. I need to chose one and click same (text) li element all the time. This function document.getElementsByTagName("li")[5].click() works, but sometimes index change and pres wrong line. i have same value all the time like "222" but index may be different, how to .click not by tag name, but text?

<ul>
            <li>111</li>
            <li>222</li>
            <li>333</li>
            <li>444</li>
</ul>

thanks,

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

You have to iterate through li and check content of each one

for (element in document.getElementsByTagName("li")) {
  if (element.textContent === '222') {
    element.click();
    break;
  }
}

https://www.w3schools.com/jsref/prop_node_textcontent.asp

Or you can try to build querySelector. But I'm not sure if it supports content. https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

about 4 years ago · Santiago Gelvez 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