Last active
October 6, 2015 21:48
-
-
Save ljepson/3058442 to your computer and use it in GitHub Desktop.
Find any element Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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