Skip to content

Instantly share code, notes, and snippets.

@krutz27
Created October 4, 2013 13:37
Show Gist options
  • Select an option

  • Save krutz27/6826055 to your computer and use it in GitHub Desktop.

Select an option

Save krutz27/6826055 to your computer and use it in GitHub Desktop.
//search within text
$.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