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 5957769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:26:55+00:00 2026-05-22T18:26:55+00:00

I have an expanding menu using jquery. It works well except for one thing:

  • 0

I have an expanding menu using jquery. It works well except for one thing: when the user navigates away from the page the menu collapses. I want the menu to stay open when the user clicks on any of the final < li > links. All of these links open the same page. Content on these pages is grabbed from a database and determined by the ?id=.

Here’s the code:

HTML:

 <ul id="nav">
    <li><a href="javascript:;">Products</a>
           <ul id="nav2">
        <li><a href="javascript:;">Domestic Market</a>
            <ul>
                <li><a href="index.php?page=Product&id=1">Link1</a></li>
                    <li><a href="index.php?page=Product&id=2">Link2</a></li>
                    <li><a href="index.php?page=Product&id=3">Link3</a></li>
        </ul>
       </li>
       <li><a href="javascript:;">Commercial Market</a>
            <ul>
                <li><a href="">Coming Soon</a></li>
            </ul>
       </li>
      </ul>
       </li>
       </ul>

CSS:

ul {
    padding: 0px;
    margin: 0px;
    width: 10em;
        list-style-type:none;

}
li {
     font: 100% Verdana, Arial, Helvetica, sans-serif;
 font-size:12px;
 color:#003;  
}

li ul {
    display: none;
}
li.active > ul {
    display: block;
}

jQuery:

$('#nav').delegate('li,a', 'click', function(e) {
    e.stopPropagation();

    var self = $(e.target),
        //get a reference to the clicked element
        active = self.parents().andSelf() //select all li's that should be active
        .addClass('active'); //and activate them
    $('#nav .active').not(active).removeClass('active'); //deactivate others  
});

$(document).click(function(){
    $('.active').removeClass('active'); 
});

How do I keep the final < li >’s open?

  • 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-05-22T18:26:56+00:00Added an answer on May 22, 2026 at 6:26 pm

    I would recommend storing the value in a cookie and then setting it on page load.

    First off, I’d recommen you download the jQuery cookie plugin here.
    It’s a good plugin and it’s small. Set the value:

    $.cookie("cookie_name", "cookie_value");
    

    And then on document.ready you can pull the value:

    $.cookie("cookie_name);
    

    and set it appropriately with something resembling your current click function.

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

Sidebar

Related Questions

I have a bunch of divs that I am expanding/retracting individually using .toggle and
I have two divs stacked one above the other, with my code expanding the
I'm using a jQuery UI accordion as a menu on the right side of
I have an application which resides in menu bar, pretty much like this one
I have a page in which expanding content flows out of the holding div,
I have a menu on the left of my page that is made of
I have created a UserControl using a DevExpress XtraTreeList. Basically in this user control
In one Android activity I have added a context menu to an ImageView with
I have a wcf dataservice I am calling from Silverlight and I am expanding
I have Visual Studio 2008 Professional and I am having issues with expanding and

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.