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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:39:56+00:00 2026-06-04T09:39:56+00:00

Im building this menu but I’m having a problem with excluding a parent and

  • 0

Im building this menu but I’m having a problem with excluding a parent and its children. I hope to solve this without extra classes.

So the way it suppose to work is to click a a.clicked and it .hide() the li elements outside its own li but with in the scope of the ul

its no problem finding the parent ul and put a class on the li which i do li.active. The hard thing here becomes to exclude all the elements inside the li.active.
It do sound messy so i try to comment as best i can in the script.

Thanks guys for input

EDIT: i done a poor job explaining but like i click level 1 - 1and level 1 - 2 is suppose to hide and thats the pattern as we go deeper down the menu with 2 – 1 ect

first of here is the demo: http://jsfiddle.net/Abj9u/6/

$('.clicked').on('click', function(){
    var $this = $(this);

    //activate this li
    $this.parent('li:first').addClass('active');

    //hide the other level (1)(2)(3)(4)(ect..) li items
    //is there a way to exlude .active li and its children without adding a class like .sub to the sub li's?
    $this.parents('ul:first').find('li').not('.active').hide();

    //add class to this for style
    $this.addClass('selected');

    //show the sub ul
    $this.parent().children('ul:first').show();
});​

html

<ul id="nav">
    <li>
        <a href="#" class="clicked">Level 1 - 1</a>

        <ul class="hidden">
            <li><a href="#" class="clicked">Level 2.1 - 1</a>
                <ul class="hidden"><li><a href="#" class="clicked">Level 3.1 - 1</a></li></ul>                
            </li>
            <li><a href="#" class="clicked">Level 2.2 - 1</a>
                <ul class="hidden"><li><a href="#" class="clicked">Level 3.2 - 1</a></li></ul>                
            </li>
            <li><a href="#" class="clicked">Level 2.3 - 1</a>
                <ul class="hidden"><li><a href="#" class="clicked">Level 3.3 - 1</a></li></ul>                
            </li>
        </ul>                
    </li>

    <li>
        <a href="#" class="clicked">Level 1 - 2</a>

        <ul class="hidden">
            <li><a href="#" class="clicked">Level 2.1 - 2</a>
                <ul class="hidden"><li><a href="#" class="clicked">Level 3.1 - 2</a></li></ul>                
            </li>
            <li><a href="#" class="clicked">Level 2.2 - 2</a>
                <ul class="hidden"><li><a href="#" class="clicked">Level 3.2 - 2</a></li></ul>                
            </li>
            <li><a href="#" class="clicked">Level 2.3 - 2</a>
                <ul class="hidden"><li><a href="#" class="clicked">Level 3.3 - 2</a></li></ul>                
            </li>
        </ul>                
    </li>
</ul>​
  • 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-04T09:40:01+00:00Added an answer on June 4, 2026 at 9:40 am

    Maybe this:

    $(this).closest('li').siblings().hide()
    

    as for why this works, it’s fairly self explanatory:

    • starting from this child element…
    • find the first parent LI…
    • then find all of this LI’s siblings…
    • hide them.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this annoying problem with padding. I am building a menu, here is
I am building a menu with Razor and having a problem with it displaying
Sorry for such a trivial question, but I'd feel silly building this if it
So I am building a site for a client. The problem is the menu
I am building a small dropdown menu with jQuery, but i am have a
Here im building a tree menu. A category is accessed by its id and
I have looked around for a solution to this problem, but it's so wonky
I'm building a drop-down menu this way: var htmlString = '<select id=sAddress>'; for (var
I am building a menu in jQuery using .animate() but I've run into a
i'm building a webpage for livestreamers from my website. but i'm having some problems

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.