R
RC
I want to recursively go through to an element node.
Here are the simple lines
<a href="#" onClick="startANode('ul1')">Recursive Read</a>
<ul id="ul1">
<li>line 1<b>bold 1<i>italic 1<u>under 1</u></i></b></li>
<li><b><i><u>line 2</u></i></b></li>
<li><b><i><u>line 3</u></i></b></li>
<li><b><i><u>line 4</u></i></b></li>
<li><b><i><u>line 5</u></i></b></li>
</ul>
But my java script only goes through the line 1. It never
goes through line 2 to line 5. Can you help me find the problem
in my script?
Thank Q in advance!
BTW, why DOM has firstChild, lastChild but doesn't have nextChild?
Here is the java script
<script type="text/javascript">
function startANode(id) {
var thisNode = document.getElementById(id);
recursiveRead(thisNode);
}
function recursiveRead(node) {
//alert(id);
if (! node.hasChildNodes()) {
alert(
"Node name = " + node.nodeName + "\n" +
"Node value = " + node.nodeValue + "\n" +
"Node type = " + node.nodeType + "\n" +
"Node id = " + node.id + "\n" +
"Node data = " + node.data + "\n"
);
} else {
nodeList = node.childNodes;
alert(nodeList.length);
for (var i = 0; i < nodeList.length; i++) {
aNode = nodeList;
recursiveRead(aNode);
}
}
}
</script>
Here are the simple lines
<a href="#" onClick="startANode('ul1')">Recursive Read</a>
<ul id="ul1">
<li>line 1<b>bold 1<i>italic 1<u>under 1</u></i></b></li>
<li><b><i><u>line 2</u></i></b></li>
<li><b><i><u>line 3</u></i></b></li>
<li><b><i><u>line 4</u></i></b></li>
<li><b><i><u>line 5</u></i></b></li>
</ul>
But my java script only goes through the line 1. It never
goes through line 2 to line 5. Can you help me find the problem
in my script?
Thank Q in advance!
BTW, why DOM has firstChild, lastChild but doesn't have nextChild?
Here is the java script
<script type="text/javascript">
function startANode(id) {
var thisNode = document.getElementById(id);
recursiveRead(thisNode);
}
function recursiveRead(node) {
//alert(id);
if (! node.hasChildNodes()) {
alert(
"Node name = " + node.nodeName + "\n" +
"Node value = " + node.nodeValue + "\n" +
"Node type = " + node.nodeType + "\n" +
"Node id = " + node.id + "\n" +
"Node data = " + node.data + "\n"
);
} else {
nodeList = node.childNodes;
alert(nodeList.length);
for (var i = 0; i < nodeList.length; i++) {
aNode = nodeList;
recursiveRead(aNode);
}
}
}
</script>