Here's my stripped down function for recursing through a browsers dom structure.
(function () {
function displaydom (child, parent) {
if (parent) {parent = parent+".";}; // if there is no parent then child is the parent
var jsns = eval(parent+child); // Join parent + child and eval
for (var i in jsns){ // loop through dom object's attributes
if (typeof jsns[i] == "object") { // if attribute is an object then recurse through
// display output here
displaydom (String(i) /** next child **/, parent+child);
};
};
};
displaydom ('self', '');
})();
There are a couple - probably simple - problems with it that I haven't been able to get to work (in Chrome):
- need to remove eval()
- I want to change the for loop to
for (var i=0, len = jsns.length; i < len; i++) {};
because it's faster but I keep getting length for jsns '0' or 'undefined'.
P.S - Don't try and run the code as is unless you want your browser to crash!