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.