I have 2 show / hide buttons of 2 groups: group1 and group2. When I click to open group1, for example, it opens a card with information from that group and when I click hide it it hides.
So far so good!
What I want is that when I click on the other group (group2), instead of opening the group2 under what was already open (group1), I want it to click close the group1 to open the new one.
<button type="button" class=" grupo1 btn-toggle btn waves-effect waves-light green" data-element="#grupo1">
Mostrar / Esconder
</button>
<button type="button" class=" grupo2 btn-toggle btn waves-effect waves-light green" data-element="#grupo2">
Mostrar / Esconder
</button>
<div class="grupos row">
<div class="col s12 m6 l3" id="grupo1" style="display:none">
<div class="card">
<div class="card-content green darken-2 white-text">
</div>
</div> </div> </div>
<div class="grupos row">
<div class="col s12 m6 l3" id="grupo2" style="display:none">
<div class="card">
<div class="card-content green darken-2 white-text">
</div>
</div> </div> </div>
// Função do button Mostrar/Esconder do card
$(function(){
$(".btn-toggle").click(function(e){
e.preventDefault();
el = $(this).data('element');
$(el).toggle();
});
});