Skip to content

Instantly share code, notes, and snippets.

@ljepson
Last active October 6, 2015 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljepson/3058442 to your computer and use it in GitHub Desktop.
Save ljepson/3058442 to your computer and use it in GitHub Desktop.
Find any element Javascript
// Put in the element you want to find.
var el = document.getElementsByTagName("a"),
// Enter your search term
st = 'whatever',
// Results will go here when done
res;
for(var i = 0; i < el.length; i++) {
// Checking to see if the returned element's innerText matches the search term
if(el[i].innerText === st) {
// Results have been saved if anything was found. You can now use the variable res to do whatever you'd like
res = el[i];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment