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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:54:39+00:00 2026-06-17T15:54:39+00:00

If I click "Media," it slides down and displays the sub links. I then

  • 0

If I click "Media," it slides down and displays the sub links. I then click on "Items" and it also slides down exposing its links within. How can I hide "Media" when I click on "Items?"

HTML code

<ul id="nav">
<li><a href="#" class="collapse">Media</a>
    <ul>
        <li><a href="#">Photos</a></li>
        <li><a href="#">Video</a></li>
        <li><a href="#">Audio</a></li>
        </ul>
</li>
<li><a href="#" class="collapse">Items</a>
    <ul>
        <li><a href="#">Add</a></li>
        <li><a href="#">List</a></li>
        </ul>
</li>
</ul>

JS Code

// Collapsable navigation
$('ul#nav .collapse:not(.open)').parents('li').find('ul').hide();

$('ul#nav .collapse').click(function() {
    if( ! $(this).hasClass('open') ) {
        $(this).parents('li').find('ul').stop(true, true).slideDown('fast');
        $(this).addClass('open');
    } else {
        $(this).parents('li').find('ul').stop(true, true).slideUp('fast');
        $(this).removeClass('open');
    }
      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-17T15:54:39+00:00Added an answer on June 17, 2026 at 3:54 pm

    The accordion logic is pretty simple, here’s a commented version:

    $('#nav .collapse').click(function () {
        //stores a reference to the `ul` which will be toggled
        var toToggle = $(this).closest('li').find('ul');
        //hide the others
        $('#nav ul').not(toToggle).slideUp(200);
        //toggle the clicked one
        toToggle.slideToggle(200);
        return false;
    });
    

    Fiddle


    You can make the code even shorter by removing the unnecessary variable but then it loses some readability:

    $('#nav .collapse').click(function () {
        $('#nav ul').not(
            $(this).closest('li').find('ul').slideToggle(200)
        ).slideUp(200);
        return false;
    });
    

    Fiddle

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

Sidebar

Related Questions

Protected Sub lnkContractors_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkContractors.Click If Context.User.IsInRole("HOD")
I know I can do this: $("#my_div").live("click", function() { alert("My Div was clicked"); }
I know we can have this in 1.4: $("a").bind({ click : clickFn, mouseover: mouseFn
I've a table generated dynamically by jQuery, using this.html("<table><tr><td><div>Click Me</div></td></tr></table>"); within the table, I've
I have the following code that works on Firefox and Chrome $("#adicionarItem").click(function(){ $.ajax({ type:
I am doing this: <div onclick='alert("xxx")'>Click me!</div> and I see that alert but I
If the HTML is like: <a href="javascript:void(0)" id="link">Click Me</a> and I set the eventHandler
The click event should work fine: subMenu = $(.sub-menu) //.... subMenu.show() $(a.mobile).click (e) ->
I intercept all the click events in my iframe with this code: $(doc.body).on("click", function(e)
I've looked at all these posts: jQuery stop fadein during fadeout jQuery stop "click"

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.