Skip to content

Instantly share code, notes, and snippets.

@solomon081
Created June 17, 2012 00:34
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 solomon081/2942991 to your computer and use it in GitHub Desktop.
Save solomon081/2942991 to your computer and use it in GitHub Desktop.
searchInElements
/**
* @author Solomon Wise
*/
"use strict";
var domTools = {};
domTools.searchInElements = function (elem, pattern) {
if (pattern.constructor !== RegExp) {
throw "Pattern must be a RegExp";
}
if (elem.constructor !== String) {
throw "Element must be a String";
}
elem = document.getElementsByTagName(elem);
var matches = [];
for (e = 0; e < elem.length; e++) {
if (pattern.test(elem[e].innerHTML)) {
matches.push(elem[e]);
}
}
return matches;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment