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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:19:01+00:00 2026-06-14T07:19:01+00:00

I have a main menu that will display the submenus with a click event

  • 0

I have a main menu that will display the submenus with a click event in jquery (client wanted to be click instead hover) so I got it working however I still can’t figure out one thing: I have the menu and submenus working properly so when I click on “news” the submenu slides down nicely and when I click back on “news” it closes back, however if after openening news’ submenu and I click on “resources” the respective submenu appears but news’ submenu stays open, I want the previous submenu to close when clicking on another menu item or outside the main menu area any ideas? here’s what I got:

<ul id="MainMenu">
        <li><a href="#">Home</a></li>
        <li><a href="#">About Us</a></li>
        <li>
              <a href="#">News</a>
              <ul class="noJS">
                <li><a href="#">sub menu 1</a></li>
                <li><a href="#">sub menu 2</a></li>
                <li><a href="#">sub menu 3</a></li>
                <li><a href="#">sub menu 4</a></li>
                <li><a href="#">sub menu 5</a></li>
                <li><a href="#">sub menu 6</a></li>
            </ul>                         
        </li>
        <li><a href="#">Jobs</a></li>
        <li><a href="#">Contact Us</a></li>
        <li><a href="#">Admin</a></li>
        <li>
            <a href="#">Resources</a>
            <ul class="noJS">
                <li><a href="#">sub menu 1</a></li>
                <li><a href="#">sub menu 2</a></li>
                <li><a href="#">sub menu 3</a></li>
                <li><a href="#">sub menu 4</a></li>
                <li><a href="#">sub menu 5</a></li>
                <li><a href="#">sub menu 6</a></li>
            </ul>
        </li>
        <li class="lastChild"><a href="#">New Button</a></li>
    </ul>

and the jquery:

    $(function(){
$('#MainMenu').find('> li').click(function(){
    $(this).find('ul')
    .stop(true, true).slideToggle(400); 
    return false;       
});    
});
  • 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-14T07:19:02+00:00Added an answer on June 14, 2026 at 7:19 am

    Try something like this

    $(function() {
        $('#MainMenu > li').click(function(e) { // limit click to children of mainmenue
            var $el = $('ul',this); // element to toggle
            $('#MainMenu > li > ul').not($el).slideUp(); // slide up other elements
            $el.stop(true, true).slideToggle(400); // toggle element
            return false;
        });
        $('#MainMenu > li > ul > li').click(function(e) {
            e.stopPropagation();  // stop events from bubbling from sub menu clicks
        });
    });​
    

    http://jsfiddle.net/Ssu32/

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

Sidebar

Related Questions

I have an app that so far consists of two Activities: The Main Menu
I have an application that lives in the menubar, without a main menu or
I have created a jQuery menu which will open when clicking on a small
I want to create a context menu using C# that will display next to
I have a main menu activity with a bunch of buttons. One button starts
I have a main menu window. On clicking any menu item it opens a
I'm currently working on a game and I wish to have a main menu
I have a menu item Home in my main menu AND in my top
I have a log out button on my main menu and I want it
I have an NSMenu (let's say the Main Menu), with lots of NSMenu s

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.