title: How to keep the current Accordion active on page refresh in Bootstrap
body: <p>I have following code of Accordion. The code is working fine. I want to keep the selected tab active on page refresh. But the javascript I have added is not working. I am not getting as to what is the exact problem.</p>
  <pre><code>&lt;div class=&quot;accordion&quot; id=&quot;accordionExample&quot;&gt;
    &lt;div class=&quot;card&quot;&gt;
      &lt;div class=&quot;card-header&quot; id=&quot;headingOne&quot;&gt;
        &lt;h2 class=&quot;mb-0&quot;&gt;
          &lt;button class=&quot;btn btn-link&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#collapseOne&quot; aria-expanded=&quot;false&quot; aria-controls=&quot;collapseOne&quot;&gt;
            Collapsible Group Item #1
          &lt;/button&gt;
        &lt;/h2&gt;
      &lt;/div&gt;
  
      &lt;div id=&quot;collapseOne&quot; class=&quot;collapse show&quot; aria-labelledby=&quot;headingOne&quot; data-parent=&quot;#accordionExample&quot;&gt;
        &lt;div class=&quot;card-body&quot;&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=&quot;card&quot;&gt;
      &lt;div class=&quot;card-header&quot; id=&quot;headingTwo&quot;&gt;
        &lt;h2 class=&quot;mb-0&quot;&gt;
          &lt;button class=&quot;btn btn-link collapsed&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#collapseTwo&quot; aria-expanded=&quot;false&quot; aria-controls=&quot;collapseTwo&quot;&gt;
            Collapsible Group Item #2
          &lt;/button&gt;
        &lt;/h2&gt;
      &lt;/div&gt;
      &lt;div id=&quot;collapseTwo&quot; class=&quot;collapse&quot; aria-labelledby=&quot;headingTwo&quot; data-parent=&quot;#accordionExample&quot;&gt;
        &lt;div class=&quot;card-body&quot;&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=&quot;card&quot;&gt;
      &lt;div class=&quot;card-header&quot; id=&quot;headingThree&quot;&gt;
        &lt;h2 class=&quot;mb-0&quot;&gt;
          &lt;button class=&quot;btn btn-link collapsed&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#collapseThree&quot; aria-expanded=&quot;false&quot; aria-controls=&quot;collapseThree&quot;&gt;
            Collapsible Group Item #3
          &lt;/button&gt;
        &lt;/h2&gt;
      &lt;/div&gt;
      &lt;div id=&quot;collapseThree&quot; class=&quot;collapse&quot; aria-labelledby=&quot;headingThree&quot; data-parent=&quot;#accordionExample&quot;&gt;
        &lt;div class=&quot;card-body&quot;&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>Javascript</strong></p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
  $(document).ready(function(){
      $('button[data-toggle=&quot;collapse&quot;]').on('shown.bs.collapse', function(e) {
          localStorage.setItem('activeTab', $(e.target).attr('data-target'));
      });
      var activeTab = localStorage.getItem('activeTab');
      if(activeTab){
          $('#accordionExample button[data-target=&quot;' + activeTab + '&quot;]').collapse('show');
      }
  });
  &lt;/script&gt;
  </code></pre>