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

218
Views
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 answers
Answer question

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