b24
asked on
Hide/Expand menu with javascript
Hi experts,
I have a html menu that is automatically generated by a Java object and I don’t have any control over what it produces. The menu which it outputs is included below.
I need this menu to expand in an accordion like manner with javascript. The links entitled 'Primary Link' should always be present but their sublinks entitled 'Secondary link' should only be visible when you hover on the primary/parent link.
Does anyone know how i might go about doing this without having to alter the html?
Any help would be greatly appreciated.
Looking forward to hearing from you.
I have a html menu that is automatically generated by a Java object and I don’t have any control over what it produces. The menu which it outputs is included below.
I need this menu to expand in an accordion like manner with javascript. The links entitled 'Primary Link' should always be present but their sublinks entitled 'Secondary link' should only be visible when you hover on the primary/parent link.
Does anyone know how i might go about doing this without having to alter the html?
Any help would be greatly appreciated.
Looking forward to hearing from you.
<ul>
<li class="link_selected"><a href="cms.jsp?menu_id=5638" >Primary Link 1</a></li>
<li class="link"><a href="cms.jsp?menu_id=6313" >Primary Link 2</a>
<ul>
<li class="link"><a href="cms.jsp?menu_id=6314" >Secondary Link 1</a></li>
<li class="link"><a href="cms.jsp?menu_id=5644" >Secondary Link 2</a></li>
<li class="link"><a href="cms.jsp?menu_id=5642" >Secondary Link 3</a></li>
<li class="link"><a href="cms.jsp?menu_id=6542" >Secondary Link 4</a></li>
<li class="link"><a href="cms.jsp?menu_id=6486" >Secondary Link 5</a></li>
<li class="link"><a href="cms.jsp?menu_id=5641" >Secondary Link 6</a></li>
</ul>
</li>
<li class="link"><a href="cms.jsp?menu_id=6488" >Primary Link 3</a>
<ul>
<li class="link"><a href="cms.jsp?menu_id=6493" >Secondary Link 6</a></li>
<li class="link"><a href="cms.jsp?menu_id=6494" >Secondary Link 7</a></li>
<li class="link"><a href="cms.jsp?menu_id=6495" >Secondary Link 8</a></li>
<li class="link"><a href="cms.jsp?menu_id=6496" >Secondary Link 9</a></li>
<li class="link"><a href="cms.jsp?menu_id=6497" >Secondary Link 10</a></li>
<li class="link"><a href="cms.jsp?menu_id=6498" >Secondary Link 11</a></li>
<li class="link"><a href="cms.jsp?menu_id=6492" >Secondary Link 12</a></li>
</ul>
</li>
<li class="link"><a href="cms.jsp?menu_id=6543" >Primary Link 4</a></li>
<li class="link"><a href="cms.jsp?menu_id=6489" >Primary Link 5</a></li>
</ul>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and off-course the secondary links will hidden first, isn't it?
ASKER
But the primary and secondary links all have the same class="link" so how would it know which ones to hide and expand on hover?
The primary links should always be visible and the secondary links should only be visible when you hover on the primary link to which they belong.
Thanks for your help!
The primary links should always be visible and the secondary links should only be visible when you hover on the primary link to which they belong.
Thanks for your help!
doesn't matter. which ever link is hovered only that link's children will be shown, if they exists
You can assign another class to the secondary links to make them invisible earlier.
You can assign another class to the secondary links to make them invisible earlier.
ASKER
Thanks. I'll give it a try.