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

  • Home
  • SEARCH
  • 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 8909077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:20:43+00:00 2026-06-15T03:20:43+00:00

How do I stop the accordion menu ul.sub-menu from closing when a submenu link

  • 0

How do I stop the accordion menu ul.sub-menu from closing when a submenu link is clicked?

The accordion opens fines when the parent item is clicked, but when the submenu item is clicked in the level beneath it, it closes again.

Here’s my HTML:

<ul class="menu">
  <li><a href="#">parent 1</a>
        <ul class="sub-menu">
            <li><a href="#">1st child item</a></li>
        </ul>
  </li>
    <li><a href="#">parent 2</a>
    <ul class="sub-menu current-menu-parent">
        <li><a href="#">2nd child item</a></li>
        <li class="current-menu-item"><a href="#">3rd child item</a></li>
    </ul>
  </li>
  <li><a href="#">parent 3</a>
        <ul class="sub-menu">
            <li><a href="#">4th child item</a></li>
        </ul>
  </li>    
</ul>​​​​​​​​

Here’s my jquery:

jQuery(function($) {
    $(".menu > li").children("a").attr('href', 'javascript:void(0)');
    $('.sub-menu').hide();  
    $('.current-menu-parent').show();    
    $('.menu > li').click(function() {
        $(this).find('ul').slideToggle('slow');
    });
});​
  • 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-15T03:20:44+00:00Added an answer on June 15, 2026 at 3:20 am

    Accordion for you,

    HTML :

    <ul class="menu">
      <li><a href="javascript:void(0)">parent 1</a>
            <ul class="sub-menu">
                <li><a href="#">1st child item</a></li>
            </ul>
      </li>
        <li><a href="javascript:void(0)">parent 2</a>
        <ul class="sub-menu current-menu-item">
            <li><a href="#">2nd child item</a></li>
            <li><a href="#">3rd child item</a></li>
        </ul>
      </li>
      <li><a href="javascript:void(0)">parent 3</a>
            <ul class="sub-menu">
                <li><a href="#">4th child item</a></li>
            </ul>
      </li>    
    </ul>​​​​​​​​
    

    CSS:

    <style>
    .sub-menu{
        display:none;
    }
    .current-menu-item{
        display:block;
    }
    </style>
    

    JS:

    rel = 0;
    
    
    $('.sub-menu').hover(function(){ // findind mouse postion
            rel = 1; // if mouse on submenu
        }, function(){ 
            rel = 0;  if mouse out submanu
    });
    $('.menu > li').live("click",function(){
    
    
            if(!$(this).hasClass("active")){ // if not already opened
                $('.sub-menu').slideUp();    // hide all other submenu
                $('.sub-menu',this).slideDown();  // show which your clicked
                $(".menu > li").remove('active');  //  remove all active class in li
                $(this).addClass('active'); //adding active class which your clicked li
            }
            else{
                if(rel==0){
                    $('.sub-menu').slideUp(); // if clicked already opend parent that will close
                    $(this).removeClass('active'); // remove all active class
                }
                else{
    
                }
            }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vertical accordion menu that opens on hover, stays open and closes
I'm trying to make an accordion-like menu with jQuery, but it refuses to cooperate:
I have the accordion below which works but when an item is open if
How can i stop propagation for link? <script src=http://code.jquery.com/jquery.min.js></script> <script> $(function() { $(#g).click(function(event){ alert(Link
I'm trying to stop using the arrow keys in vim. But instead of setting
I want to stop the end users from being able to resize a GUI
How do I stop my application from going back when the user clicks on
how to I stop a Video from playing and go back to start? videoPlayer.currentPlaybackTime
when I click the link hide information link it shows Show information but it
I am new to Jquery but have written a simple vertical accordion. It seems

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.