search for text in a page


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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. };

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.