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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:16:23+00:00 2026-06-11T03:16:23+00:00

How would you appropriately code the jquery for the below list containing the <a>

  • 0

How would you appropriately code the jquery for the below list containing the <a> tags. I’m having two problems.

  1. When I click the parent list item to reveal the child item, the parent item disappears and is simply replaced by an indented child item on the same line.

  2. Somewhat related, I can for some reason click the last element of “1” “2” “3” and “4” resulting in the list actually disappearing. How can i fix this problem?

HTML:

<div class="main_list">
   <ul>
     <li><a href="#">1.</a>
       <ul>
         <li><a href="#">1.1</a>
           <ul>
             <li><a href="#">1.1.1</a></li>
           </ul>
         </li>
       </ul>
     <li><a href="#">2.</a></li>
     <li><a href="#">3.</a>
       <ul>
         <li><a href="#">3.1</a></li>
         <li><a href="#">3.2</a></li>
       </ul>
     <li><a href="#">4.</a>
       <ul>
         <li><a href="#">4.1</a>
           <ul>
             <li><a href="#">4.1.1 </a></li>
             <li><a href="#">4.1.2 </a></li>
           </ul>
         </li>
       </ul>
     </li>
   </ul>
</div>

JQUERY:

$(document).ready(function(){

// only show top level elements to begin
$("ul ul").hide();


$("li").click(function(){
    $(this).children().toggle(500);
    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-11T03:16:25+00:00Added an answer on June 11, 2026 at 3:16 am

    Use children("ul") to only toggle the ul children of the parent item li. Otherwise, you’ll toggle the parent item, <a href="#">1.</a>, which is also a child of li:

    $("li").click(function(){
        $(this).children("ul").toggle(500);
        return false;
    });
    

    DEMO.

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

Sidebar

Related Questions

I have a curious problem in jQuery regarding order of execution. The code below
What algorithm would you use to create an application that given appropriate data (list
I'm having issues with google adsense and it loading before my jQuery and killing
I'm using jquery to change/animate bg positions of a menu item, but I need
So the old JavaScript aficionado and the young jQuery wizard in me are having
Yesterday I attempted to ask a question why my jquery-ui Datepicker code wasn't working,
I was looking through the jQuery code and found this line: elem.runtimeStyle.left = elem.currentStyle.left;
So I currently have a jQuery dialog with two buttons: Save and Close. I
I am having an issue with a single line of javascript/jquery. I am attempting
would it be appropriate to use PHP's sscanf to read user submitted sentences and

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.