Hi RobG,
I'm wondering about this line:
node = node || document.getElementsByTagName('html')[0];
Is there a reason why you use document.getElementsByTagName('html')[0]
and not document.documentElement? I haven't explored browser issues
with document.documentElement, so maybe that's it? Just wondering if
one is preferable to the other, and why.
Genuinely curious,
--Karl
____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On May 20, 2009, at 9:57 PM, RobG wrote:
On May 20, 8:35 pm, Sourabh <sourabhmkulka...@gmail.com> wrote:
Hi
I am new to jQuery.I have a problem where I want to traverse through
DOM.For example a complete webpage.Is there any jQuery way to
traverse
complete DOM of the current page where the jQuery script resides ?
Traversing the DOM is trivial, using recursion it requires perhaps 4
lines of plain javascript. What do you actually want to do?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<title>domWalk</title>
<script type="text/javascript">
function domWalk(node) {
node = node || document.getElementsByTagName('html')[0];
// do something with node
console.log(node.nodeName + ':' + node.nodeType);
if (node.childNodes) {
for (var i=0, len=node.childNodes.length; i<len; i++) {
domWalk(node.childNodes[i]);
}
}
}
window.onload = function(){domWalk()};
</script>
<div><p></div>
--
Rob