Вот моя урезанная функция для повторения через структуру dom браузеров.
(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', '');
})();
Есть пара проблем, вероятно, простых, с которыми я не смог добраться до работы (в Chrome):
- нужно удалить eval ()
- Я хочу изменить цикл for на
for (var i=0, len = jsns.length; i < len; i++) {};
, потому что он быстрее, но я продолжаю получать длину для jsns '0' или 'undefined'.
P.S. - Не пытайтесь запускать код как есть, если только вы не хотите, чтобы ваш браузер зависал!