Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
Button collapses/expands accordions only on second click Bootstrap

I have this button that collapses/expands all accordions on the page when clicked. The Problem is when I first load the page it will only starting collapsing/expanding everything after I click a second time on the button, then it works on every click.

Button HTML:

<Button id="collapseAll" class="btn btn-secondary">Collapse/Expand</Button>

Button JS:

$("#collapseAll").click( function() {
        if(!$('.accordion-header').hasClass("active")){
            $('.accordion-header').removeClass("active").addClass("active");

        } else {
            $('.accordion-header').addClass("active").removeClass("active");
        }
    });
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

$( document ).ready(function() {
    $("#collapseAll").click( function() {
            if(!$('.accordion-header').hasClass("active")){
                $('.accordion-header').removeClass("active").addClass("active");

            } else {
                $('.accordion-header').addClass("active").removeClass("active");
            }
        });

});
about 4 years ago · Juan Pablo Isaza Report

0

I think the problem is with your css code.

you can add the following css and it should work fine..

.accordion-header{
      display:none;
}

.accordion-header.active{
     display:block;
}
about 4 years ago · Juan Pablo Isaza Report

0

Validate if it matches your requirement. Also you can refer the link http://accordion-cd.blogspot.com/

$(document).ready(function () {
    $("#accordion").accordion({
      collapsible:true,
  });
var icons = $( "#accordion" ).accordion( "option", "icons" );
$('.open').click(function () {
$('.ui-accordion-header').removeClass('ui-corner-all').addClass('ui-accordion-header-active ui-state-active ui-corner-top').attr({
    'aria-selected': 'true',
        'tabindex': '0'
      });
$(this).attr("disabled","disabled");
$('.close').removeAttr("disabled");
});    
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!