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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:30:09+00:00 2026-06-08T23:30:09+00:00

The basic idea is that I have a bunch of div’s in which each

  • 0

The basic idea is that I have a bunch of div’s in which each can be toggled (show/hide).

When one div is toggled I’d like for other div’s that are currently being shown to hide, thus only allowing one single div to be shown at a time.

In addition I’d like to be able to click outside the element to hide the open div as well.

Just to make things clearer I provided an example which currently does everything I want except closing a div when opening another (Only one div open at a time functionality):

$(document).ready(function(){

  $('div.dropdown').each(function() {
    var $dropdown = $(this);

    $("a.dropdown-link", $dropdown).click(function(e) {
      e.preventDefault();
      $("div.dropdown-container", $dropdown).toggle();
      return false;
    });

});
    
  $('html').click(function(){
    $("div.dropdown-container").hide();
  });
     
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div id="dropdown-1" class="dropdown dropdown-processed">
  <a class="dropdown-link" href="#">Options</a>
  <div class="dropdown-container" style="display: none;">
    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
    </ul>
  </div>
</div>

<div id="dropdown-2" class="dropdown dropdown-processed">
  <a class="dropdown-link" href="#">Options</a>
  <div class="dropdown-container" style="display: none;">
    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
    </ul>
  </div>
</div>

<div id="dropdown-3" class="dropdown dropdown-processed">
  <a class="dropdown-link" href="#">Options</a>
  <div class="dropdown-container" style="display: none;">
    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
    </ul>
  </div>
</div>
  • 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-08T23:30:11+00:00Added an answer on June 8, 2026 at 11:30 pm

    You basically just need to hide all divs except the one being toggled:

    $(document).ready(function(){
    
      $('div.dropdown').each(function() {
        var $dropdown = $(this);
    
        $("a.dropdown-link", $dropdown).click(function(e) {
          e.preventDefault();
          $div = $("div.dropdown-container", $dropdown);
          $div.toggle();
          $("div.dropdown-container").not($div).hide();
          return false;
        });
    
    });
        
      $('html').click(function(){
        $("div.dropdown-container").hide();
      });
         
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <div id="dropdown-1" class="dropdown dropdown-processed">
      <a class="dropdown-link" href="#">Options</a>
      <div class="dropdown-container" style="display: none;">
        <ul>
          <li>Item 1</li>
          <li>Item 2</li>
          <li>Item 3</li>
        </ul>
      </div>
    </div>
    
    <div id="dropdown-2" class="dropdown dropdown-processed">
      <a class="dropdown-link" href="#">Options</a>
      <div class="dropdown-container" style="display: none;">
        <ul>
          <li>Item 1</li>
          <li>Item 2</li>
          <li>Item 3</li>
        </ul>
      </div>
    </div>
    
    <div id="dropdown-3" class="dropdown dropdown-processed">
      <a class="dropdown-link" href="#">Options</a>
      <div class="dropdown-container" style="display: none;">
        <ul>
          <li>Item 1</li>
          <li>Item 2</li>
          <li>Item 3</li>
        </ul>
      </div>
    </div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the basic idea is that you have some class that has a reference type
Basic question here - I have many lines of code that look something like:
The basic idea is that I have a family of classes that all do
The basic idea is that I have a native function I want to call
The basic idea of what we are trying to do is that we have
I have basic idea on Kilo Virtual Machine on Mobiles , I have clear
I have some basic idea on how to do this task, but I'm not
I have a basic implementation of alpha-beta pruning but I have no idea how
Say I have a LINQ-to-XML query that generates an anonymous type like this: var
I have a question that might seem basic but I just cannot figure out

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.