Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda