Eleandro Duzentos
asked on
Recursive walk through DOM elements strange behavior
I'm trying to make a function that walks recursively through the elements bellow:
This is the code that makes it:
The problem is that, its not working as expected, it is only resolving until the last <span class="line line-3"></span> and stops there when <section class="presentation"></sec tion> still remaining to be resolved. What i'm doing wrong?
<body>
<main class="main">
<header class="e200-header">
<a class="umburg side-item" href="#">
<div>
<span class="line line-1"></span>
<span class="line line-2"></span>
<span class="line line-3"></span>
</div>
</a>
</header>
<section class="presentation">
</section>
</main>
</body>
This is the code that makes it:
function recursiveResolve(node) {
if (typeof node != 'undefined') {
//node.someMethod = aFunction
var l = node.childElementCount
if (l) {
childrens = node.children
for (var i = 0; i < l; i++) {
recursiveResolve(childrens[i])
}
}
}
}
recursiveResolve(document.body)
The problem is that, its not working as expected, it is only resolving until the last <span class="line line-3"></span> and stops there when <section class="presentation"></sec
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You saved my day!!! Thank you so much!!!