title: Invoke Bootstrap Accordion via JavaScript
body: <p>I want to use the accordion on my site, however I'd prefer to use it over javascript plugin rather than html markup. I would like to have two buttons which open different content, however make only one visible at a time. After reading the documentation I figured that if they have the same parent selector it would work. Could anyone take a look at this fiddle and tell me where do I go from here?</p>
  
  <p><a href="http://jsfiddle.net/krasnoludojad/q7962oxp/" rel="nofollow">http://jsfiddle.net/krasnoludojad/q7962oxp/</a></p>
  
  <p>HTML</p>
  
  <pre><code>&lt;div class="container-fluid" id="accordion"&gt;
      &lt;div class="navbar-header"&gt;
          &lt;button type="button" class="btn btn-default" id="btn-collapse-menu"&gt;MENU&lt;/button&gt;
          &lt;button type="button" class="btn btn-default" id="btn-collapse-login"&gt;LOGIN&lt;/button&gt;
      &lt;/div&gt;
      &lt;div class="collapse navbar-collapse" id="navbar-collapse-menu"&gt;
          &lt;nav&gt;
              &lt;ul class="list-unstyled text-center"&gt;
                  &lt;li&gt;&lt;h3 href="#"&gt;BLOG&lt;/h3&gt;&lt;/li&gt;                
              &lt;/ul&gt;
          &lt;/nav&gt;
      &lt;/div&gt;
      &lt;div class="collapse navbar-collapse" id="navbar-collapse-login"&gt;
          &lt;p&gt;Lorem ipsum.&lt;/p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>$('#btn-collapse-menu').on('click', function(){     
      $('#navbar-collapse-menu').collapse('toggle', {
          parent: "#accordion"
      });             
  });
  $('#btn-collapse-login').on('click', function(){        
      $('#navbar-collapse-login').collapse('toggle', {
          parent: "#accordion"
      });             
  });
  </code></pre>
  
  <h3>UPDATE</h3>
  
  <p>Well I've come up with a temporary solution, which I'm not that happy about so I would still appreciate the answer to mechanics behind working this out with parent option. For now I've patched with javascript by checking if the class <code>.in</code> exists that comes when the field is being shown</p>
  
  <pre><code>$('#btn-collapse-menu').on('click', function(){     
      $('#navbar-collapse-login').hasClass('in') ? $('#navbar-collapse-login').collapse('hide') : null;
      $('#navbar-collapse-menu').collapse('toggle');
  });
  $('#btn-collapse-login').on('click', function(){
      $('#navbar-collapse-menu').hasClass('in') ? $('#navbar-collapse-menu').collapse('hide') : null;
      $('#navbar-collapse-login').collapse('toggle');             
  });
  </code></pre>