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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:16:08+00:00 2026-05-30T12:16:08+00:00

As this is my first post here, I would like to thank all of

  • 0

As this is my first post here,
I would like to thank all of you very much for your great support.

Now to the point…

I have 2 accordions in one page.
How can I prevent having 2 accordion tabs expanded?
I mean, if a tab from the first accordion is expanded, I want this tab to be collapsed, when click a tab from the second accordion.

Spent many hours searching over the net and Stack Overflow, but found nothing.

Example Code:

Javascript:

$(function() {
  $( ".myAccordion" ).accordion({
collapsible: true,
active: -1
});
});

Html:

<div>Category One</div>
<div class="myAccordion">
   <h3>Title1</h3>
   <div>Text1</text>
   <h3>Title2</h3>
   <div>Text2</text>
 </div>

<div>Category Two</div>
<div class="myAccordion">
   <h3>Title1</h3>
   <div>Text1</text>
   <h3>Title2</h3>
   <div>Text2</text>
 </div>

I tried adding a changestart option:

changestart: function(event, ui) {
  $('h3.ui-accordion-header').removeClass('ui-state-active ui-corner-top').addClass('ui-state-default ui-corner-all');
  $('div.ui-accordion-content').slideUp();
  $('div.ui-accordion-content').removeClass('ui-accordion-content-active ui-corner-top').addClass('ui-corner-all');
  $('span.ui-icon').removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e');
}

This does the trick, but only for the first time, a tab is clicked.
When you click that tab for a second time, it doesn’t change at all. You have to click it for a third time to get it expand again.

Any help will be very appreciated.
Thanks again…

  • 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-30T12:16:09+00:00Added an answer on May 30, 2026 at 12:16 pm

    After I played a little and didn’t find any solution, I decided to leave ui-accordion and make my own one! I believe that was the best solution to my problem!

    As I didn’t need fancy styling I used this code to achieve the result I needed:

    <body>
    
     <h1>Category 1</h1>
     <div class="accTabs">
          <a class="accLink" href="#">
            <div class="tab-title">Tab Title</div>
            <div class="tab-slide" style="display:none;">Tab Content to Slide</div>
          </a>
     </div>
     <div class="accTabs">
          <a class="accLink" href="#">
            <div class="tab-title">Tab Title</div>
            <div class="tab-slide" style="display:none;">Tab Content to Slide</div>
          </a>
     </div>
    
     <h1>Category 2</h1>
     <div class="accTabs">
          <a class="accLink" href="#">
            <div class="tab-title">Tab Title</div>
            <div class="tab-slide" style="display:none;">Tab Content to Slide</div>
          </a>
     </div>
     <div class="accTabs">
          <a class="accLink" href="#">
            <div class="tab-title">Tab Title</div>
            <div class="tab-slide" style="display:none;">Tab Content to Slide</div>
          </a>
     </div>
    
    
    <script>
    $("a.accLink").click(function () {
        var $that = $(this),
            $children = $that.children('div.tab-slide');
    
        // If expanded tab was clicked, collapse it.
        // >> FIXED LOGIC ERROR >> if ($children.hasClass("slided")) {
        if ($that.hasClass("slided")) {
            $children.slideUp("slow", function () {
                $that.removeClass("slided");
            });
        } else {
            // Collapse all expanded tabs
            // FIXED LOGIC ERROR >> $("div.slided").slideUp("slow", function() {
            $(".slided").find("div.tab-slide").slideUp("slow", function () {
                $(".slided").removeClass("slided");
            });
            // Expand clicked tab
            $children.slideDown("slow", function () {
                $that.addClass("slided");
            });
        }
    });
    </script>
    </body>
    

    UPDATED SCRIPT: FIXED LOGIC ERRORS TO MAKE 100% FUNCTIONAL

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

Sidebar

Related Questions

this is my first post here and i like to thank all the people
this is my first post here on stackoverflow and am very impressed by the
um, first post here, this place seems to be all over google and i
My very first post here! I have been using this site for many years
Background First of all, much gratitude to atebits for their very informative blog post
First of all, I've looked at EVERY other post here, about this (I think)
This is my first post here so go easy. I am trying to build
This is my first post here. I have a problem. I need to take
My first post here, so i hope this is the right area. I am
I'm new to Java and this is my first post on here so hopefully

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.