title: Bootstrap 4 Accordion Toggle All
body: <p>I am trying to toggle the state of <em>all</em> accordion items by clicking a button. By default I want them all to be closed. The button should either <code>Open All</code> or <code>Close All</code>.</p>
  
  <p>According to the <a href="https://getbootstrap.com/docs/4.0/components/collapse/#collapsetoggle" rel="nofollow noreferrer">docs</a> I should be able to use the <code>toggle()</code> method?</p>
  
  <p>I have included my current code below with a fiddle link.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;button id="toggleAccordions" class="btn btn-primary" type="button" data-toggle="collapse"&gt;Open / Close&lt;/button&gt;
  
  &lt;div id="accordion" role="tablist"&gt;
    &lt;div class="card"&gt;
      &lt;div class="card-header" role="tab" id="headingOne"&gt;
        &lt;h5 class="mb-0"&gt;
          &lt;a data-toggle="collapse" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne"&gt;
            Collapsible Group Item #1
          &lt;/a&gt;
        &lt;/h5&gt;
      &lt;/div&gt;
  
      &lt;div id="collapseOne" class="collapse" role="tabpanel" aria-labelledby="headingOne" data-parent="#accordion"&gt;
        &lt;div class="card-body"&gt;
          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.
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="card"&gt;
      &lt;div class="card-header" role="tab" id="headingTwo"&gt;
        &lt;h5 class="mb-0"&gt;
          &lt;a class="collapsed" data-toggle="collapse" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"&gt;
            Collapsible Group Item #2
          &lt;/a&gt;
        &lt;/h5&gt;
      &lt;/div&gt;
      &lt;div id="collapseTwo" class="collapse" role="tabpanel" aria-labelledby="headingTwo" data-parent="#accordion"&gt;
        &lt;div class="card-body"&gt;
          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.
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="card"&gt;
      &lt;div class="card-header" role="tab" id="headingThree"&gt;
        &lt;h5 class="mb-0"&gt;
          &lt;a class="collapsed" data-toggle="collapse" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree"&gt;
            Collapsible Group Item #3
          &lt;/a&gt;
        &lt;/h5&gt;
      &lt;/div&gt;
      &lt;div id="collapseThree" class="collapse" role="tabpanel" aria-labelledby="headingThree" data-parent="#accordion"&gt;
        &lt;div class="card-body"&gt;
          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.
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JQuery</strong></p>
  
  <pre><code>$(function() {
    $('#toggleAccordions').on('click', function(e) {
      $('#accordion .collapse').collapse('toggle')
    })
  });
  </code></pre>
  
  <p><a href="https://jsfiddle.net/johnny_s/org5cyr9/" rel="nofollow noreferrer">Fiddle</a>.</p>
  
  <p>Any help is appreciated.</p>