By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

Iterating though nodes

P: n/a
I'm trying to iterate through nodes in a Selection Range, but I'm
having a bit of trouble determining why all nodes in the range aren't
being hit. It seems like deeply nested nodes aren't being hit for some
reason.

Here's the code I'm using.

var n = startNode;
while (n) {
this.visited.push('[' + n.nodeName + ']');

if (n == endNode) {
break;
}

if (n != startNode && n.hasChildNodes()) {
n = n.firstChild;
} else {
while (!n.nextSibling) {
n = n.parentNode;
}
n = n.nextSibling;
}
}

Nov 1 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
pr
matth wrote:
I'm trying to iterate through nodes in a Selection Range, but I'm
having a bit of trouble determining why all nodes in the range aren't
being hit. It seems like deeply nested nodes aren't being hit for some
reason.

Here's the code I'm using.

var n = startNode;
while (n) {
this.visited.push('[' + n.nodeName + ']');

if (n == endNode) {
break;
}

if (n != startNode && n.hasChildNodes()) {
n = n.firstChild;
} else {
while (!n.nextSibling) {
n = n.parentNode;
}
n = n.nextSibling;
}
}
Hello again. That code won't retrieve nodes that are children of the
startNode, because you only visit firstChild for subsequent nodes. Is
that the difficulty? Could you supply URLs of pages that fail?
Nov 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.