Skip to content

Instantly share code, notes, and snippets.

@yasu00000
Created February 11, 2011 01:50
Show Gist options
  • Save yasu00000/821777 to your computer and use it in GitHub Desktop.
Save yasu00000/821777 to your computer and use it in GitHub Desktop.
Text Search
$.fn.egrep = function(pat) {
var out = [];
var textNodes = function(n) {
if (n.nodeType == Node.TEXT_NODE) {
var t = typeof pat == 'string' ?
n.nodeValue.indexOf(pat) != -1 :
pat.test(n.nodeValue);
if (t) {
out.push(n.parentNode);
}
}
else {
$.each(n.childNodes, function(a, b) {
textNodes(b);
});
}
};
this.each(function() {
textNodes(this);
});
return out;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment