I've created a menu using the accordion, and everything seems to be working correctly except for one small detail. When I select a sub-menu item, the sub-menu does not remain "open" when visiting the selected page. That's how it should work, isn't it? I'm sure there is something obvious missing, but I don't see it. The active tags appear to be set correctly. I'd appreciate some help from the community with this one.
Here's the relevant code:
- <script type="text/javascript">
- var nav = 0;
- $('.sub-menu').hover(function () { // finding mouse position
- nav = 1; // if mouse on submenu
- }, function () {
- nav = 0; // if mouse not on submenu
- });
- $(document).ready(function () {
- $('#nav > li > a').click(function () {
- if ($(this).attr('class') != 'active') {
- $('#nav li ul').slideUp();
- $(this).next().slideToggle();
- $('#nav li a').removeClass('active');
- $(this).addClass('active');
- }
- else {
- if (nav == 0) {
- $('.sub-menu').slideUp();
- $(this).removeClass('active');
- }
- //$('#nav li ul').slideUp();
- //$('#nav li a').removeClass('active');
- }
- });
- });
- $(function () {
- // this will get the full URL at the address bar
- var url = window.location.href;
- // passes on every "a" tag
- $("#menu_block a").each(function () {
- // checks if its the same on the address bar
- if (url == (this.href)) {
- $(this).closest("li").addClass("active");
- }
- });
- });
- </script>
- ...
- <div id="menu_block">
- <ul id="nav" class="menu_item">
- <li id="menuIndex" runat="server"><asp:HyperLink ID="hypIndex" runat="server" NavigateUrl="index.aspx">Home</asp:HyperLink></li>
- <li id="menuViewProfile" runat="server"><asp:HyperLink ID="hypViewProfile" runat="server" NavigateUrl="~/secure/profile.aspx">View Profile</asp:HyperLink></li>
- <li id="menuChartering" runat="server"><asp:HyperLink ID="hypChartering" runat="server" NavigateUrl="~/secure/chartering.aspx">Chartering</asp:HyperLink></li>
- <li id="menuRegistry" runat="server" style="cursor:pointer"><asp:HyperLink ID="hypRegistry" runat="server">Registry</asp:HyperLink>
- <ul class="sub-menu">
- <li id="menuNotified" runat="server"><asp:HyperLink ID="hypNotified" runat="server" NavigateUrl="~/secure/notified.aspx">Notified</asp:HyperLink></li>
- <li id="menuAuthorized" runat="server"><asp:HyperLink ID="hypAuthorized" runat="server" NavigateUrl="~/secure/authorized.aspx">Authorized</asp:HyperLink></li>
- <li id="menuResearch" runat="server"><asp:HyperLink ID="hypResearch" runat="server" NavigateUrl="~/secure/research.aspx">Research</asp:HyperLink></li>
- </ul>
- </li>
- ...
- </ul>
- </div>