title: Accordion inside modal - When click on any other collapsible tab, the first one remain open
body: <p>When I open the modal the first tab by default opens up and if I click on any other tab the first tab closes and the clicked tab opens up, but then If I again click on the first tab then both the tabs opens up. Here is the html code</p>
  
  <pre><code>    &lt;body&gt;
  &lt;button id="modalButtton" type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"&gt;
    Launch demo modal
  &lt;/button&gt;   
  &lt;div class="modal fade" id="myModal" role="dialog"&gt;
      &lt;div class="modal-dialog"&gt;
  
        &lt;!-- Modal content--&gt;
        &lt;div class="modal-content"&gt;
          &lt;div class="modal-header"&gt;
            &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
            &lt;h4 id="modal-title"&gt; &lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="modal-body"&gt;
            &lt;div class="panel-group" id="accordion"&gt;
                          &lt;div class="panel panel-default"&gt;
                              &lt;div class="panel-heading"&gt;
                                  &lt;h4 class="panel-title"&gt;
                                  &lt;a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne"&gt;Course Introduction
  
                                  &lt;/a&gt;
                                  &lt;/h4&gt;
                              &lt;/div&gt;
  
                              &lt;div id="collapseOne" class="panel-collapse collapse in"&gt;
                                  &lt;div class="panel-body"&gt;
  
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="panel panel-default"&gt;
                              &lt;div class="panel-heading"&gt;
                                  &lt;h4 class="panel-title"&gt;
                                  &lt;a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo"&gt;Description
  
                                  &lt;/a&gt;
                                  &lt;/h4&gt;
                              &lt;/div&gt;
  
                              &lt;div id="collapseTwo" class="panel-collapse collapse"&gt;
                                  &lt;div class="panel-body"&gt;
                                  &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod&lt;/p&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="panel panel-default"&gt;
                              &lt;div class="panel-heading"&gt;
                                  &lt;h4 class="panel-title"&gt;
                                  &lt;a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseThree"&gt;Goals
  
                                  &lt;/a&gt;
                                  &lt;/h4&gt;
                              &lt;/div&gt;
  
                              &lt;div id="collapseThree" class="panel-collapse collapse"&gt;
                                  &lt;div class="panel-body"&gt;
                                  &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod te&lt;/p&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                      &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
            &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  
      &lt;/div&gt;
    &lt;/div&gt; &lt;!-- end of Modal --&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>Here is the jquery code</p>
  
  <pre><code>$('#myModal').on('hidden.bs.modal', function () {
  $('.collapse').collapse('hide');
  });
  $('#myModal').on('shown.bs.modal', function () {
  $('#collapseOne').collapse('show');
  });
  
  
  
  $('#accordion').find('.panel-default:has(".in")').addClass('panel-primary');
  
  $('#accordion').on('show.bs.collapse', function (e) {
  $(e.target).closest('.panel-default').addClass(' panel-primary');
  }).on('hide.bs.collapse', function (e) {
  $(e.target).closest('.panel-default').removeClass(' panel-primary');
  })
  </code></pre>