Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:46:26+00:00 2026-06-18T05:46:26+00:00

I found some menu code which is very simple and works nicely from just

  • 0

I found some menu code which is very simple and works nicely from just jquery without plugins.
What I would like to do is to make it sticky so that when a new page is linked to, that page expands the menu (if necessary) down to the linked item and highlights that item as active if the current window.location matches the tag href.
I’ve been wading through Dom console looking but I figure there must be a simpler jquery solution if I’m lucky. any suggestions on how to achieve this much appreciated.
Thanks

    $(document).ready(function() {
        $('#menu ul').hide();

  /* Note the following three lines added as working solution to original question. */
  /* works for fully qualified url: i.e. http://www.mydomain.com/mypage.ext         */
  /* also note that addClass('current') requires .current class in your css          */

        var currentLink = $("a[href='" + location.href + "']");
        currentLink.parents("ul:hidden").slideDown("normal");
        currentLink.filter('a:first').addClass('current');

  /* end of solution fix                                                             */

        $('#menu li a').click(
         function() {
           var openMe = $(this).next();
           var mySiblings = $(this).parent().siblings().find('ul');
           if (openMe.is(':visible')) {
               openMe.slideUp('normal');  
           } else {
              mySiblings.slideUp('normal');  
              openMe.slideDown('normal');
           }
       });
    });

menu is as follows:

<ul id="menu">
 <li><a href="#">1</a></li>
 <li><a href="#">2</a></li> 
 <li><a href="#">3</a>
     <ul class="submenu">
        <li><a href="#">3-1</a>
            <ul>
                <li><a href="#">3-1-1</a></li>
                <li><a href="#">3-1-2</a></li>
                <li><a href="#">3-1-3</a></li>
            </ul>
        </li>
        <li><a href="#">3-2</a>
            <ul>
                <li><a href="#">3-2-1</a></li>
                <li><a href="#">3-2-2</a></li>
            </ul>
        </li>
    </ul>
 </li>
 <li><a href="#">4</a></li>
 <li><a href="#" title="">5</a>
 <ul>
     <li><a href="#">5-1</a></li>
     <li><a href="#">5-2</a></li>
     <li><a href="#">5-3</a></li>
 </ul>
 </li>
 <li><a href="#" title="">6</a>
 <ul>
     <li><a href="#">6-1</a></li>
     <li><a href="#">6-2</a></li>
     <li><a href="#">6-3</a></li>
 </ul>
 </li>
 <li><a href="#" title="">7</a></li>
 <li><a href="#" title="">8</a>
 <ul>
     <li><a href="#">8-1</a></li>
     <li><a href="#">8-2</a></li>
     <li><a href="#">8-3</a></li>
 </ul>
 </li>
 <li><a href="#" title="">9</a></li>
</ul>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:46:27+00:00Added an answer on June 18, 2026 at 5:46 am

    Here’s the bullet-proof way to find links with matching urls:

    var currentLink = $("a").filter(function() {
        return this.href == location.href;
    });
    

    If you always use app relative URLs for your hrefs (eg href="/abc/123.htm"), you can use the attribute selector:

    var appRelativeUrl = location.pathname + location.search + location.hash;
    var currentLink = $("a[href='" + appRelativeUrl + "']");
    

    If you always use absolute URLs for your hrefs (eg href="http://mysite.com/abc/123.htm"), you can also use the attribute selector:

    var currentLink = $("a[href='" + location.href + "']");
    

    But, if you use relative urls in your HTML, use the first technique using .filter().

    Then, to expand the menu, find all the hidden parent <ul> elements and slide them down. After the parents are displayed, if you want to expand the link’s submenu, issue a click on the link:

    currentLink.parents("ul:hidden").slideDown("normal", function() {
        currentLink.click();
    });
    

    Demo here
    Demo code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found some really great code from Matt Gallagher for use with making Undo
I found some old code which I'm not sure I understand completely. The folowing
I found some sample code in Microsoft Dynamics CRM 4.0 SDK which is asking
I found some old Python code that was doing something like: if type(var) is
I found some mapkit code on the internet that looks like this: - (void)recenterMap
In my current system the menu is generated via a CustomControl code, which is
I have the following code that I wrote, which I personally found to be
I've got a small, very simple, winforms which calls one class and is writing
I'm looking to go away from our current according style menu and use jquery
I'm trying to create simple (facebook like) menu in my app. I've found several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.