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
appreciated. John
In the below script, I can expand and contract the nodes when clicked
on, but I want the menu to close all other siblings to the node
clicked so that only one sub menu option is expanded at one time. If
the node display is being set to none, I would also like it to
collapse all the sub nodes.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#level_1, #level_2, #level_3, #level_4 {
cursor:pointer;
cursor:hand;
font-weight:normal;
list-style-image:url(plus. gif);
color:#003366;
padding-bottom:5px;
}
..folderheader, .folderlist {
display:none;
}
..folderlist {
list-style-image:url(repor t.gif);
}
LI {
padding-left:2px;
}
a:visited {
color: #003366;
}
a:hover {
color: #663333;
}
a:active {
color: #003366;
}
a:link {
color: #003366;
}
..style1 {
font-size: 14pt;
font-weight: bold;
}
body {
margin-left: 15px;
}
</style>
<script language="javas cript" type="text/javascript">
var head="display:' '"
img1=new Image()
img1.src="plus. gif"
img2=new Image()
img2.src="minus .gif"
function showMenu(){
var elm=event.srcEl ement;
//unsure how to best traverse the dom here in a list
var myMenuLength;
//for(i=0;i<myMen uLength;i++){
//}
//expands or contracts the nodes clicked on
if(elm.id && elm.id.indexOf( 'level') > -1){
if (elm.childNodes (1).currentStyl e.display=="non e"){
elm.childNodes( 1).style.displa y="block"
elm.style.listS tyleImage="url( minus.gif)"
}
else{
elm.childNodes( 1).style.displa y="none"
elm.style.listS tyleImage="url( plus.gif)"
}
}
}
document.onclic k=showMenu;
</script>
</head>
<body>
<ul id="mainmenu">
<li id="level_1">Me nu 1
<ul class="folderhe ader">
<li id="level_2">Re port Types
<ul class="folderhe ader">
<li id="level_3">Re ports 1
<ul class="folderhe ader">
<li id="level_4">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
<li>Clone Records</li>
</ul>
</li>
<li id="level_4">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
<li>Mass Update</li>
<li>Clone Records</li>
</ul>
</li>
</ul>
</li>
<li id="level_3">Re ports 2
<ul class="folderhe ader">
<li id="level_4">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
<li>Mass Update</li>
<li>Clone Records</li>
</ul>
</li>
<li id="level_4">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li id="level_1">Me nu 2
<ul class="folderhe ader">
<li id="level_2">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
</ul>
</li>
</ul>
</li>
</ul>
</body>
</html>
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
appreciated. John
In the below script, I can expand and contract the nodes when clicked
on, but I want the menu to close all other siblings to the node
clicked so that only one sub menu option is expanded at one time. If
the node display is being set to none, I would also like it to
collapse all the sub nodes.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#level_1, #level_2, #level_3, #level_4 {
cursor:pointer;
cursor:hand;
font-weight:normal;
list-style-image:url(plus. gif);
color:#003366;
padding-bottom:5px;
}
..folderheader, .folderlist {
display:none;
}
..folderlist {
list-style-image:url(repor t.gif);
}
LI {
padding-left:2px;
}
a:visited {
color: #003366;
}
a:hover {
color: #663333;
}
a:active {
color: #003366;
}
a:link {
color: #003366;
}
..style1 {
font-size: 14pt;
font-weight: bold;
}
body {
margin-left: 15px;
}
</style>
<script language="javas cript" type="text/javascript">
var head="display:' '"
img1=new Image()
img1.src="plus. gif"
img2=new Image()
img2.src="minus .gif"
function showMenu(){
var elm=event.srcEl ement;
//unsure how to best traverse the dom here in a list
var myMenuLength;
//for(i=0;i<myMen uLength;i++){
//}
//expands or contracts the nodes clicked on
if(elm.id && elm.id.indexOf( 'level') > -1){
if (elm.childNodes (1).currentStyl e.display=="non e"){
elm.childNodes( 1).style.displa y="block"
elm.style.listS tyleImage="url( minus.gif)"
}
else{
elm.childNodes( 1).style.displa y="none"
elm.style.listS tyleImage="url( plus.gif)"
}
}
}
document.onclic k=showMenu;
</script>
</head>
<body>
<ul id="mainmenu">
<li id="level_1">Me nu 1
<ul class="folderhe ader">
<li id="level_2">Re port Types
<ul class="folderhe ader">
<li id="level_3">Re ports 1
<ul class="folderhe ader">
<li id="level_4">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
<li>Clone Records</li>
</ul>
</li>
<li id="level_4">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
<li>Mass Update</li>
<li>Clone Records</li>
</ul>
</li>
</ul>
</li>
<li id="level_3">Re ports 2
<ul class="folderhe ader">
<li id="level_4">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
<li>Mass Update</li>
<li>Clone Records</li>
</ul>
</li>
<li id="level_4">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li id="level_1">Me nu 2
<ul class="folderhe ader">
<li id="level_2">Re port Name
<ul class="folderli st">
<li>Add New Record</li>
<li>Edit Records</li>
</ul>
</li>
</ul>
</li>
</ul>
</body>
</html>
Comment