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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:59:33+00:00 2026-05-24T01:59:33+00:00

http://jsfiddle.net/yrM3H/2/ I have the following code: jQuery(document).ready(function() { jQuery(.toggle).next(.hidden).hide(); jQuery(.toggle).click(function() { $(‘.active’).toggleClass(‘active’).next(‘.hidden’).slideToggle(300); $(this).toggleClass(‘active’).next().slideToggle(fast); });

  • 0

http://jsfiddle.net/yrM3H/2/

I have the following code:

jQuery(document).ready(function() {
  jQuery(".toggle").next(".hidden").hide();
  jQuery(".toggle").click(function()
  { 
    $('.active').toggleClass('active').next('.hidden').slideToggle(300);
    $(this).toggleClass('active').next().slideToggle("fast");   

});
});

I have multiple <div>‘s, and my idea is that when I open a <div> it toggles another <div>. And then, when I click another <div>, it hides the open <div>. Therefore only one <div> is open at a time.

My only issue is that with this code, when I try to close a <div> that is already open, it will close and then open again. Thus one <div> will always be open.

Any help will be appreciated, thank you.

I added the HTML and CSS below. Everything works fine, except that I cannot get it so that all of them are closed.

I have 5 of these stacked on each other in a wrapper.

*edited for clarity *

// HTML
<div class="toggle"></div>
<div  class="hidden"></div>

// CSS
.toggle {width:398px; height:48px; cursor: pointer;}
.hidden {width:300px; height:75px; background-color:#333333; margin-left:50px; text-indent:25px;}
  • 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-24T01:59:33+00:00Added an answer on May 24, 2026 at 1:59 am

    This will fix it:
    http://jsfiddle.net/yrM3H/3/

      jQuery(".toggle").click(function()
      { 
        $('.active').not(this).toggleClass('active').next('.hidden').slideToggle(300);
        $(this).toggleClass('active').next().slideToggle("fast");   
      });
    

    you have to exclude the clicked element form your “.active” section using .not() since the clicked element is “.active” to.

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

Sidebar

Related Questions

I have the following code: http://jsfiddle.net/SPWWx/ I'm completely new to javascript, this is my
http://jsfiddle.net/B2rdD/3/ I've Created 25 buttons using HTML and I have written jquery code such
Even though the following works: http://jsfiddle.net/N7D5r/ My attempt at using the same code does
I need help concerning following code: http://jsfiddle.net/8PsdE/ <SELECT ID=pizzasize NAME=pizzasize> <OPTION VALUE=s>small <OPTION VALUE=m>medium
I am using this code: http://jsfiddle.net/q3nUS/ $('#cf11_field_20').change(function() { $(#li-11-22)[$(this).val() == full03_accommodation_hotel ? 'show' :
Hi I have shared the code here : http://jsfiddle.net/jTAZ4/ Why am i getting the
http://jsfiddle.net/xysxD/11/ if you check the jsfiddle Will have a comment text that slide toggle
In the following link: http://jsfiddle.net/gCvbT/ , if you click on General and then click
I have this script: http://jsfiddle.net/NV2uV/ It works, but I do not like it. Cons:
code: http://jsfiddle.net/WRppV/4/ I should get something like content=> [141, [203, 206, 204, 205], 142,

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.