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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:50:26+00:00 2026-06-10T09:50:26+00:00

I have a menu with rudimentary nested lists as below: <nav> <ul id=mainNav> <li><a

  • 0

I have a menu with rudimentary nested lists as below:

<nav>
    <ul id="mainNav">

        <li><a href="expand-the-sub-menu">Option 1</a>
            <ul class="navChild">
                <li><a href="somewhere">Option 1 Link 1</a></li>
                <li><a href="somewhere">Option 1 Link 2</a></li>
                <li><a href="somewhere">Option 1 Link 3</a></li>
                <li><a href="somewhere">Option 1 Link 4</a></li>
                <li><a href="somewhere">Option 1 Link 5</a></li>
            </ul>
        </li>

        <li><a href="expand-the-sub-menu">Option 2</a>
            <ul class="navChild">
                <li><a href="somewhere">Option 2 Link 1</a></li>
                <li><a href="somewhere">Option 2 Link 2</a></li>
                <li><a href="somewhere">Option 2 Link 3</a></li>
                <li><a href="somewhere">Option 2 Link 4</a></li>
                <li><a href="somewhere">Option 2 Link 5</a></li>
            </ul>
        </li>

        <li><a href="somewhere">Option 3</a></li>
        <li><a href="somewhere">Option 4</a></li>
        <li><a href="somewhere">Option 5</a></li>
        <li><a href="somewhere">Option 6</a></li>
    </ul>
</nav>

And I’ve written some conditional script to produce the desired animated effect, depending on the current menu state:

$('#mainNav ul').hide();

$('#mainNav>li>a').click(function(){
    var elm = this;

    // If clicked element has a sibling ul with specified class
    if ($(elm).next().hasClass('navChild')){
        // ... & another child ul is already visible
        if ($('.navChild').is(':visible')){
            $('#mainNav ul').fadeOut(300, function() {
                $(elm).siblings('ul').fadeIn(300);
            });
        // ... & no child ul is visible
        } else {
            $('nav').animate({bottom:'60px'},300,function(){
               $(elm).next().fadeIn(300);
            });
        }

    // Else clicked element has no sibling ul with specified class
    } else {
        // ... & another child ul is already visible
        if ($('.navChild').is(':visible')){
            $('#mainNav ul').fadeOut(300, function(){
                $('nav').animate({bottom:'24px'});
            });
        // ... & no child ul is visible
        } else {
            // Follow link as usual
        }
    }
});

The code may be ugly and verbose, but it works.

What I’m trying to do now is highlight the current menu item. If it’s a top-level <a> tag, then just that link should be highlighted. When in a child-level <a> tag, however, both that link and its parent link should be highlighted. Another caveat is that I’d like all child links to be in a non-active state when revealed by clicking on their parent link.

Here’s a jsFiddle http://jsfiddle.net/pHwgk that almost works, If you show, hide, then re-show a child-level <ul>, you should hopefully see what I mean – i.e. I don’t want it to remember the state it was previously in.

I’m hoping someone will have an elegant solution to save on my probably unnecessarily massive coding.

  • 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-10T09:50:28+00:00Added an answer on June 10, 2026 at 9:50 am

    Take a look at this: http://jsfiddle.net/adamzr/ku6Yj/

    I added:

    $('.navChild>li>a').each(function(){
        $(this).addClass('off');
    });
    

    to be called whenever a main level link is clicked on. It will set all the lowerlevel links to the “off” state. This should eliminate the “memory effect” as well as ensure that sublevel links appear off before they are clicked on.

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

Sidebar

Related Questions

I have menu structure like below, <ul class=sub-menu> <li class=menu-item menu-item-type-post_type menu-item-object-page menu-item-34 id=menu-item-34><a
i have menu like this <ul> <li> <a href=#>Home</a> <ul class=sub> <li>Text</li> <li>Test</li> </ul>
i have menu structure like below, <ul> <li class=menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-1406
i have menu structure like below <ul class=menu_bg id=menu-main-menu> <li class=menu-item menu-item-type-post_type menu-item-object-page menu-item-653
On the .master file i have... <div id=menu> <ul> <li class=1><a href=#>One</a></li> <li><a href=#>Two</a></li>
I have menu like that <ul id=menu> <li> <a href=/>Home</a> </li> <li class=menu-selected> <a
I have menu list that contains: <ul class=content_menu tabs> <a href=# name=content_1 class=tab active><li
I have a menu in my view: <ul> <li> <a href=<?php echo base_url(); ?>news
I have menu generated by a CMS with HTML output like: <ul id=category-nav> <li>
I have menu TABS STRUCTURE: <div id=tabs> <ul> <li><a href='#tabs-1'>TabGroup1</a></li> <li><a href='#tabs-2'>TabGroup2</a></li> </ul> <div

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.