Skip to content

@Raynos /iterateWalk.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
All the DOM recursion you'll ever need
var slice = Array.prototype.slice
function iterativelyWalk(nodes, cb) {
nodes = slice.call(nodes)
while(nodes.length) {
var node = nodes.shift(),
ret = cb(node)
if (ret) {
return ret
}
if (node.childNodes.length) {
nodes = slice.call(node.childNodes).concat(nodes)
}
}
}
function recursivelyWalk(nodes, cb) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i],
ret = cb(node)
if (ret) {
return ret
}
if (node.childNodes.length) {
var ret = recursivelyWalk(node.childNodes, cb)
if (ret) {
return ret
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.