johkar wrote:
[color=blue]
> I am confused on childNodes or children. When you have nested lists,
> I would think it would all be one list in the Dom, this doesn't seem
> to be the case. So how do you traverse an unordered list? Any help[/color]
element.childNodes returns the direct children of a element
as an array, it does not return the children of the
children. When the user clicks on a menu item, you need to
do something like (untested - for illustration only):
var a = <clickedNode>.childNodes;
for (var i=0; i<a.length; ++i) {
a[i].style.display = '';
}
As the user goes down each level, you then display the
children of each node clicked on. Once the user selects
something at the end of a branch, you then can either:
Remember all the nodes you displayed and explicity
un-display them (hideous! don't try it!) or simply travel
down the branch recursively from the top and un-display all
childNodes whether they were displayed or not (simple).
Here is a recursion routine supplied by Ryan Stewart in a
post here:
news://inetbws1.citec.qld.gov.au:119...vQ@comcast.com
Where Ryan has "out += node.nodeName + '\n';"
put in your code to undisplay the node, similar to:
n.style.display = 'none';
Here's the script:
<script type="text/javascript">
var out = "";
function listNodes(n) {
out += n.nodeName + "\n";
for (var i=0; i<n.childNodes.length; ++i) {
listNodes(n.childNodes[i]);
}
}
listNodes(document.getElementById("listMe"));
alert(out);
</script>
Good luck - Fred.