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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:30:00+00:00 2026-06-05T22:30:00+00:00

I have three info panels (divs with IDs of panel-one , panel-two and panel-three

  • 0

I have three info panels (divs with IDs of panel-one, panel-two and panel-three, all with the class info-panel) which I want to have slide in and out on the click of a link (these have the IDs toggle-one, toggle-two and toggle-three, all with the class toggle). If one of the divs is showing when one of the other links is clicked, I want to hide the visible div and show the new one. If the div’s own link is clicked, I want to toggle the show/hide. I’m using the following code to do this:

HTML:

<ul>
    <li><a id="toggle-one" class="toggle">One</a></li>
    <li><a id="toggle-two" class="toggle">Two</a></li>
    <li><a id="toggle-three" class="toggle">Three</a></li>
</ul>

<div id="panel-one" class="info-panel"><!-- content here --></div>
<div id="panel-two" class="info-panel"><!-- content here --></div>
<div id="panel-three" class="info-panel"><!-- content here --></div>

jQuery:

$("#toggle-one").click(function () {
    if($("#panel-two").is(":visible")) {
        $("#panel-two").css("z-index", "9997").hide("slide", {direction: 'up'}, 750);
    } else if($("#panel-three").css("z-index", "9997").is(":visible")) {
        $("#panel-three").css("z-index", "9997").hide("slide", {direction: 'up'}, 750);
    }
    $("#panel-one").css("z-index", "9998").toggle("slide", {direction: 'up'}, 750);
    return false;
});

$("#toggle-two").click(function () {
    if($("#panel-one").is(":visible")) {
        $("#panel-one").css("z-index", "9997").hide("slide", {direction: 'up'}, 750);
    } else if($("#panel-three").is(":visible")) {
        $("#formlink").css("z-index", "9997").hide("slide", {direction: 'up'}, 750);
    } 
    $("#panel-two").css("z-index", "9998").toggle("slide", {direction: 'up'}, 750);
    return false;
});

$("#toggle-three").click(function () {
    if($("#panel-one").is(":visible")) {
        $("#panel-one").css("z-index", "9997").hide("slide", {direction: 'up'}, 750);
    }  else if($("#panel-two").is(":visible")) {
        $("#panel-two").css("z-index", "9997").hide("slide", {direction: 'up'}, 750);
    }
    $("#panel-three").css("z-index", "9998").toggle("slide", {direction: 'up'}, 750);
    return false;
});

It works, but it’s very verbose and won’t scale well – managing three divs of info is fine, but if/when the time comes to add more, it’s going to turn into a major pain to maintain. I’ve tried using an approach like the one outlined in Show/Hide Multiple Divs with Jquery, but can’t seem to get it to work properly – the toggle and hide behaviours don’t work well (hidden dive show when they shouldn’t then immediately hide and things like that). Likewise, I can’t seem to get the example shown in Jquery toggle on 3 divs to work, either.

I’m sure there’s a much cleaner way to do this, but as I’m a bit of a jQuery and javascript n00b, I don’t really know how to go about tidying it up. What’s the best way to tackle this?

  • 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-05T22:30:04+00:00Added an answer on June 5, 2026 at 10:30 pm

    Taking a steer from what Blender posted, I ended up going with this:

    HTML:

    <div id="togglelinks">
        <ul>
            <li><a class="toggle" href="#panel-one">One</a></li>
            <li><a class="toggle" href="#panel-two">Two</a></li>
            <li><a class="toggle" href="#panel-three">Three</a></li>
        </ul>
    </div>
    
    <div id="panels">
        <div id="panel-one" class="info-panel"><!-- content here --></div>
        <div id="panel-two" class="info-panel"><!-- content here --></div>
        <div id="panel-three" class="info-panel"><!-- content here --></div>
    </div>
    

    jQuery:

    $(".toggle").click(function() {
        var $toggled = $(this).attr('href');
    
        $($toggled).siblings(':visible').hide("slide", {direction: 'up'}, 750);
        $($toggled).toggle("slide", {direction: 'up'}, 750);
    
        return false;
    });
    

    Happy with that… 27 lines of javascript down to 6, and it all seems to work! But again, many thanks are due to Blender, since I never would have got to this point otherwise.

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

Sidebar

Related Questions

Have three divs in a container that I want to float over a large
I have two controls which are both contained within a user control. Panel location:
I have three tabs.. Personal info,profile info and FinalStep... First of all i need
i have three java based web application app1,app2 and app3 at production. All 3
I have three divs, within a content div. Container width 70%. Within that I
Hy there I would like to have three apps depending, which are based on
well, the title pretty much says it all. here's a little info: i have
More of an info question, i have a panel on the left of my
i have three tables in my database book,author,publishing ... i want the user can
I have a link as bellow. Is there any way to change info@example.co.uk with

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.