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?
http://jsfiddle.net/krasnoludojad/q7962oxp/
HTML
<div class="container-fluid" id="accordion">
<div class="navbar-header">
<button type="button" class="btn btn-default" id="btn-collapse-menu">MENU</button>
<button type="button" class="btn btn-default" id="btn-collapse-login">LOGIN</button>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-menu">
<nav>
<ul class="list-unstyled text-center">
<li><h3 href="#">BLOG</h3></li>
</ul>
</nav>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-login">
<p>Lorem ipsum.</p>
</div>
</div>
JS
$('#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"
});
});
UPDATE
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 .in
exists that comes when the field is being shown
$('#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');
});