Search for objects attached to the global JS object


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

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


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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.