title: Bootstrap 4 Collapse Accordion - always have one panel open
body: <p>I'm using Bootstrap 4.0's collapse component in an accordion similar to what they have on their <a href="https://getbootstrap.com/docs/4.0/components/collapse/" rel="noreferrer">docs</a>.</p>
  
  <pre><code>&lt;div id="accordion"&gt;
    &lt;div class="card"&gt;
      &lt;div class="card-header" id="headingOne"&gt;
        &lt;h5 class="mb-0"&gt;
          &lt;button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne"&gt;
            Collapsible Group Item #1
          &lt;/button&gt;
        &lt;/h5&gt;
      &lt;/div&gt;
  
      &lt;div id="collapseOne" class="collapse show" 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" id="headingTwo"&gt;
        &lt;h5 class="mb-0"&gt;
          &lt;button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"&gt;
            Collapsible Group Item #2
          &lt;/button&gt;
        &lt;/h5&gt;
      &lt;/div&gt;
      &lt;div id="collapseTwo" class="collapse" 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" id="headingThree"&gt;
        &lt;h5 class="mb-0"&gt;
          &lt;button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree"&gt;
            Collapsible Group Item #3
          &lt;/button&gt;
        &lt;/h5&gt;
      &lt;/div&gt;
      &lt;div id="collapseThree" class="collapse" 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>So Item #1 is expanded by default. Then when you click Item #3, #1 closes and #3 expands... Perfect!</p>
  
  <p>However the default action is that if Item #3 is expanded and you click that heading, the panel closes and you're left with just a list of headings. I'd like to take it one step further where if we close Item #3, Item #1 would expand so it would be the 'default' panel that would be open if no other selection had been made.</p>
  
  <p>I've seen a <a href="https://stackoverflow.com/questions/15725717/how-do-you-make-twitter-bootstrap-accordion-keep-one-group-open">solution</a> for Bootstrap3 where one panel is always open, but I'd like to be able to have a specific panel (Item #1) as the panel that opens as a backup. This is the script for easy reference:</p>
  
  <pre><code>$('.panel-heading a').on('click',function(e){
      if($(this).parents('.panel').children('.panel-collapse').hasClass('in')){
          e.stopPropagation();
      }
      // You can also add preventDefault to remove the anchor behavior that makes
      // the page jump
      // e.preventDefault();
  });
  </code></pre>