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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:34:59+00:00 2026-05-28T13:34:59+00:00

I have two or more unordered lists with the first list item in each

  • 0

I have two or more unordered lists with the first list item in each visible and the others hidden.

When the first list itme is clicked it should show all the other li below and hide any other li’s that are open in another ul.

I cant seem to get it to show correctly.

I cannot change the class names from the example I have as they are generated deep inside core code and used for other elements.

Thanks for any help.

http://jsfiddle.net/ukkpower/En7KV/4/

  • 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-05-28T13:35:00+00:00Added an answer on May 28, 2026 at 1:35 pm

    Try this:

    $('ul').on('click','.maincat',
               function(e){
                   // prevents the default click action of the a element
                   e.preventDefault();
    
                   // finds the sibling elements, and shows them if hidden,
                   // hides them if visible
                   $(this).siblings().toggle();
    
                   // finds the closest ul ancestor of the clicked element
                   // finds the other ul siblings of that ancestor-ul
                   // finds the '.maincat' class element's siblings that are visible
                   // hides those visible elements
                  $(this)
                     .closest('ul')
                     .siblings('ul')
                     .find('.maincat')
                     .siblings('li:visible')
                     .hide();
               });
    

    JS Fiddle demo.


    Edited to add references (below) and this note:

    Please be aware that, as of jQuery 1.7, the live() method is deprecated (and, as such, support may, or more likely will be dropped). For jQuery 1.7+ use the on() method (see the references, below) and prior to 1.7 the delegate() method is recommended in preference.

    My reference for this note is the API documentation for live(), see references.

    Please note

    References:

    • closest().
    • delegate().
    • e.preventDefault().
    • find().
    • hide().
    • live().
    • on().
    • siblings().
    • toggle().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I have two (maybe more) unordered lists which are sortable with
I have two models, Image and Tag . Each Image object can have more
I have two (or more) widgets, e.g. A and B, which should launch the
I have two divs sr-left-checks and sr-right-checks. they both contain unordered lists. The left
Say I have an unordered list, like so: <ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li>
I have two or more tables which hold values under the same column name.
suppose you have two (or more) classes with private member vectors: class A {
Is this possible to have two (or more) different kinds of cells to be
I have a two or more forms on my page in a row. I'm
I have two arrays, one is very large (more than million entries) and other

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.