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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:37:26+00:00 2026-06-01T04:37:26+00:00

I am attempting to make a simple accordion where the user clicks on level

  • 0

I am attempting to make a simple accordion where the user clicks on level 1 to see level 2, clicks on level two to see level three and so on. Level 1 will be duplicated many times so i am using the .children method to avoid all the levels 2’s opening when level 1 is clicked.

The problem is when level 2 is clicked it opens level 3 but also closes level 1. I could target each directly to solve this issue but i want to do it with the minimum amount of code. Any suggestions would be much appreciated.

<div class="level1">
Level 1
    <div class="level2">
    Level 2
        <div class="level3">
        Level 3
        </div>
    </div>
</div>

<script type="text/javascript">

$(document).ready(function(){
    $('.level1').click(function(){
        $(this).children('.level2').slideToggle('300');
        }); 
});
</script>
  • 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-01T04:37:28+00:00Added an answer on June 1, 2026 at 4:37 am

    You can make that more generic (so you can easily add more levels later like):

    <div class="level1 acc">
    Level 1
        <div class="level2 acc">
        Level 2
            <div class="level3 acc">
            Level 3
            </div>
        </div>
    </div>
    
    (function($) {
        $('.acc').click(function(){
            $(this).children('div').slideToggle('300');
    
            return false; // this prevents event bubbling (thus preventing the behavior you have now) 
        }); 
    })(jQuery);
    

    Demo: http://jsfiddle.net/PeeHaa/7gAzx/

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

Sidebar

Related Questions

I am attempting to make a simple game using C++ and OpenGL and I
I'm attempting to make a simple query library and I'm using PDO for database
Attempting to make a NSObject called 'Person' that will hold the login details for
I'm attempting to make a Google Map which allows the user to check off
I'm attempting to make the switch from Windows to ubuntu (am using 12.04 LTS)
I'm writing a simple console client-server app using MSMQ. I'm attempting to run it
I was attempting to make a simple pokemon text game in c++. I created
I am attempting to make a simple class that serializes itself to disk when
I am attempting to make two elements on different sides of their container. In
I am attempting to make a simple connection to a remote database. I can

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.