Return to Snippet

Revision: 21580
at December 15, 2009 18:16 by sveggiani


Initial Code
$.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;
};

Initial URL
http://www.catswhocode.com/blog/10-jquery-snippets-for-efficient-developers

Initial Description

                                

Initial Title
search for text in a page

Initial Tags
jquery

Initial Language
JavaScript