Posted By

sveggiani on 12/15/09


Tagged

jquery not-mine


Versions (?)

search for text in a page


 / Published in: JavaScript
 

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

  1. $.fn.egrep = function(pat) {
  2. var out = [];
  3. var textNodes = function(n) {
  4. if (n.nodeType == Node.TEXT_NODE) {
  5. var t = typeof pat == 'string' ?
  6. n.nodeValue.indexOf(pat) != -1 :
  7. pat.test(n.nodeValue);
  8. if (t) {
  9. out.push(n.parentNode);
  10. }
  11. }
  12. else {
  13. $.each(n.childNodes, function(a, b) {
  14. textNodes(b);
  15. });
  16. }
  17. };
  18. this.each(function() {
  19. textNodes(this);
  20. });
  21. return out;
  22. };

Report this snippet  

You need to login to post a comment.