a button to close all opened accordion Bootstrap

Acasisme

I want to ask how to make a button to closing all opened accordion (Still toggle). The button function just to close when one of the accordion is opened. Maybe it's something weird, where the accordion has a toggle already. but in my case I need an external button to closing an opened accordion item.

I hope I can find the answer here, Thank You!

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container py-3">
<div class="accordion" id="accordionExample">
  <div class="card">
    <div class="card-header" id="headingOne">
      <h5 class="mb-0">
        <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
          Collapsible Group Item #1
        </button>
      </h5>
    </div>

    <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
      <div class="card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-header" id="headingTwo">
      <h5 class="mb-0">
        <button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          Collapsible Group Item #2
        </button>
      </h5>
    </div>
    <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
      <div class="card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
  <div class="card">
    <div class="card-header" id="headingThree">
      <h5 class="mb-0">
        <button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
          Collapsible Group Item #3
        </button>
      </h5>
    </div>
    <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionExample">
      <div class="card-body">
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      </div>
    </div>
  </div>
</div>
<br>
<a class="btn btn-primary" href="#" role="button">Button Close</a>
</div>

Lalji Tadhani

Add hide method collapse('hide') Reference

$(document).ready(function(){
  $(".btn-close").on('click', function () {
     $('.collapse').collapse('hide')
  });
});

https://jsfiddle.net/lalji1051/moafbcn5/6/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular UI Bootstrap Popover - How close all opened popover

Bootstrap button to close all collapsible element

close opened tab using jquery on close button

Can Bootstrap 4 navbar toggler button, close previously opened menu before opening another one?

Bootstrap Avoid navbar-toggle button to close opened sub menus on mobile

Close other panels when one of the panel opened in accordion

Getting Accordion Elements to automatically close When Others Are Opened

jQuery Accordion arrow icons with seperate close button

Bootstrap modal close button

close bootstrap offcanvas by button

Closing parent accordion needs to close all children accordion

Extjs accordion close all panel dynamically

Angularjs - UI Boostrap: Accordion Open and close all

Bootstrap accordion won't collapse other elements when one is opened

Trying to change the background color of the Bootstrap accordion title when opened

Close all modals bootstrap

Close all opened Windows by ONE CMD Command

Close all divs except the one that is opened with childs

Trying to close all opened forms in visual basic

How to close all the opened Sqlite Connections?

Will opened database connections still be opened after a "close-all"?

W3 Accordion - Auto close sections and open/close all

Collapse all and still have the first accordion opened by default

How to collapse all opened accordion using ZURB Foundation 6

How to change (-,+) symbol with a button Bootstrap Accordion?

Button with link inside Bootstrap accordion table

Adjust Bootstrap accordion button height based on text

Clicking on a radio button explicitly coded to close all bootstrap accordions opens them all instead

How to bind event with all bootstrap accordion