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

164
Views
Is there a way to get a website element by the visible text?

I am just starting to learn some basics of javascript related to html. I would like to know is there a way to select the html element by its visible text?

For example: If I would like to click the “Interesting” button on the stackfoverflow page I can find the element by querySelector.

stack overflow html page code sample:

<a class="youarehere is-selected flex--item s-btn s-btn__muted s-btn__outlined" 
    href="?tab=interesting" 
    data-nav-xhref="" 
    title="Questions that may be of interest to you based on your history and tag preference" 
    data-value="interesting" data-shortcut="">
        Interesting
</a>

one way of locate the html element:

document.querySelector("a[class='youarehere is-selected flex--item s-btn s-btn__muted s-btn__outlined']").click()

I know there might be some other ways to locate the element, but am I able to locate the element by the visable text “Interesting”? Thanks if anyone knows how.

stack overflow page html sample image down below.

stack overflow html sample

about 4 years ago · Juan Pablo Isaza
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!