Utilizing HTML templates based on Bootstrap 4.3.1, I am delivering educational content to my students. In the current setup, all accordion panels are closed when the page loads, and each panel can be opened independently of others.
To see a live example, visit this CodePen link: https://codepen.io/hagelslag1001/pen/MWGeZJr
Here is the HTML code snippet:
<h2>Accordion: Group of 2</h2>
<p class="small">Accordion: start copy</p>
<!-- Accordion headings should be changed to respect page hierarchy -->
<div class="accordion shadow mb-5">
<div class="card">
<div class="card-header">
<h2 class="card-title">
Accordion 1 of 2
</h2>
</div>
<div class="collapse">
<div class="card-body">
<p>Insert Accordion 1 of 2 content here.</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<h2 class="card-title">
Accordion 2 of 2
</h2>
</div>
<div class="collapse">
<div class="card-body">
<p>Insert Accordion 2 of 2 content here.</p>
</div>
</div>
</div>
</div>
<p class="small">Accordion: end copy</p>
Is there a way to modify this default setting so that only one panel can be open at a time? (Meaning, whenever a new panel opens, the previously open panel closes automatically)
The Bootstrap examples utilize (
data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne"
) to achieve this behavior for accordions in the provided templates
I'm struggling to implement this feature because the structure of the accordion HTML in these templates differs from the Bootstrap 4 examples, which typically use an 'a' or 'button' tag to trigger collapsible events.