]|V|[agnus
08-17-2004, 06:41 PM
I am trying to write a function to expand submenu options from a main menu. All options in a list. I want to use getNextSibling to avoid unecessary class or id attributes in my markup.
<!-- example markup -->
<ul id="nav">
<li><a href="#">option 1</a></li>
<li>
<a href="#" onclick="expandSubmenu(this)">option 2</a>
<ul>
... submeny options ...
</ul>
</li>
</ul>
// script
function expandSubmenu(parent) {
subnav = parent.getNextSibling().display;
if ((subnav == "")||(subnav == "none")) {
subnav = "block";
} else {
subnav = "none";
}
return false;
}
The submenus are hidden by default with JS. Accessibility zealots fear not, the parent links in my actual code would be followed to a secondary representation of the information if JS is disabled. This is what I've started with, but at this point Firefox JS console is telling me "parent.getNextSibling is not a function". Where am I going wrong?
<!-- example markup -->
<ul id="nav">
<li><a href="#">option 1</a></li>
<li>
<a href="#" onclick="expandSubmenu(this)">option 2</a>
<ul>
... submeny options ...
</ul>
</li>
</ul>
// script
function expandSubmenu(parent) {
subnav = parent.getNextSibling().display;
if ((subnav == "")||(subnav == "none")) {
subnav = "block";
} else {
subnav = "none";
}
return false;
}
The submenus are hidden by default with JS. Accessibility zealots fear not, the parent links in my actual code would be followed to a secondary representation of the information if JS is disabled. This is what I've started with, but at this point Firefox JS console is telling me "parent.getNextSibling is not a function". Where am I going wrong?