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

190
Views
How do I make collapse sections close when another collapsible element is expanded?

I'm currently having some trouble with creating a collapsible element in bootstrap 5. What I want is other sections to close when a different collapsible element is clicked (similar to an accordion). I want it so that only one section can be opened at a time.

Bootstraps collapse element is neat; however, I cannot find an example on their documentation site where other content collapses when one is expanded. I did some research, and a lot of people have been saying to use the data-parent element, but unfortunately, I'm having no luck with it.

Lets say I want to be able to make this happen with one of Bootstraps examples:

<p>
  <a class="btn btn-primary" data-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
    Link with href
  </a>
  <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
    Button with data-bs-target
  </button>
</p>
<div class="collapse" id="collapseExample">
  <div class="card card-body">
    Some placeholder content for the collapse component. This panel is hidden by default but revealed when the user activates the relevant trigger.
  </div>
</div>

How would I go about this to ensure that an opened section closes when a different collapse element on the page is hit? This code example is the first one on this page: https://getbootstrap.com/docs/5.0/components/collapse/

Thank you very much for your help.

about 4 years ago · Juan Pablo Isaza
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!