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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:44:16+00:00 2026-06-03T00:44:16+00:00

I have an accordion which closes one element when another is clicked, as well

  • 0

I have an accordion which closes one element when another is clicked, as well as simply clicking once to open and twice to close (accordionButton).
All is working well apart from the adding and removing of two classes, which control if it has an open or close arrow ‘accordionButtonActive’ & ‘accordionButtonNotactive’ As this is being controlled on click it’s not removing and adding the new class if it’s closed by clicking another one rather than clicking again to close which works perfectly.

I’m new to Jquery and was chuffed I managed to get this working as far as I have, now I’m a little baffled to making this last part function as it should.

JQuery:

    $("div.accordionButton").addClass("accordionButtonNotactive");

//ACCORDION BUTTON ACTION
$('div.accordionButton').click(function() {

    if($(this).next().is(':visible')) {
        $('div.accordionContent').slideUp('normal');
          $(this).addClass("accordionButtonNotactive").removeClass("accordionButtonActive");

    } else {
        $('div.accordionContent').slideUp('normal');    
        $(this).next().slideDown('normal');
        $(this).removeClass("accordionButtonNotactive").addClass("accordionButtonActive"); 

    }
});

    //OPEN FIRST    
$("#open").trigger('click');


    });

Simple HTML:

  <div class="accordionButton" id="open">Title</div>
  <div class="accordionContent">
    <p>Content</p>
  </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-03T00:44:18+00:00Added an answer on June 3, 2026 at 12:44 am

    You could just remove the active-class and add the inactive-class for any sibling, when any header is clicked:

    $(this).siblings('.accordionButtonActive')
        .removeClass('accordionButtonActive')
        .addClass('accordionButtonNotactive');
    

    Example

    Additionally, you might find it easier to add one style for .accordionButton and overwrite that for .accordionButton.active, so that you only have to deal with one class.

    You could also use toggleClass, in order to only have to deal with that one class once, for your current element, rather than using addClass in one condition, and removeClass in another.

    Example

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

Sidebar

Related Questions

I have a vertical accordion which opens perfectly fine when starting to open the
I have the accordion below which works but when an item is open if
I have an Accordion control to which I have added a datagrid. The problem
I have a jquery accordion which I want to add rows to. I can
I have a jQuery accordion in a page in ASP:Net MVC application in which
I have a page which has DIVs which contain short phrases (one-two words) of
I have an Accordion built with MooTools which works great. jsfiddle example: http://jsfiddle.net/T6WX7/ However,
I have well-formed xml (open-tags are closed, etc), but there's no dtd, namespaces are
i have 2 tables, i want to add rows from one table to another,
I have this JSON (which validates according to JSONLint ): [ { "BugCount":"2", "BugTitle":"C:\\INETPUB\\WWWROOT\\CLUBREADY2\\TRAINERS\\../Connections/LTC.asp",

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.