Posted By

richt on 09/15/11


Tagged

search DOM


Versions (?)

Search for objects attached to the global JS object


 / Published in: JavaScript
 

Simple recursive function to find objects that match the value of str hanging anywhere off the global JS object (window).

  1. function findInDOM(str, root, tree) {
  2. if(!root)
  3. root = window;
  4. if(root.length<1)
  5. return;
  6. for(var i in root) {
  7. if(i.indexOf(str) != -1)
  8. console.log((tree || "window") + "." + i);
  9. if('[object Object]' === Object.prototype.toString.apply(root[i]))
  10. findInDOM(str, root[i], (tree || "window") + "." + i);
  11. }
  12. }
  13.  
  14. findInDOM("get");

Report this snippet  

You need to login to post a comment.