What happens is that if I open a div when I click on another button it opens the same div and they are all open. What I want is that when you click on a button to open the div, close the div that is currently open.
Jquery
$(document).ready(function(){
$("body").on('click', '#botao_ver_opcoes', function(e) {
var id_jogador_bloqueado = $(this).data("id-jogador");
$('#opcoes-'+id_jogador_bloqueado+'').toggle();
event.stopPropagation();
$(document).click(function(){
$('#opcoes-'+id_jogador_bloqueado+'').hide();
});
});
});
HTML
<div id="show_jogadores" style="width: 150px; height: 30px; border: 1px solid #c2c5cd; text-align: center; line-height: 28px; float: left; border-right: none; cursor: pointer;">
<p>Escolha uma opção</p>
</div>
<div style="width: 30px; height: 30px; border: 1px solid #c2c5cd; text-align: center; line-height: 28px; float: left; cursor: pointer;">
<i id="botao_ver_opcoes" data-id-jogador="{{ $deleted_players->id }}" class="fa fa-angle-down" aria-hidden="true"></i>
</div>
<div id="opcoes-{{ $deleted_players->id }}" style="width: 180px; margin-top: 30px; background-color: white; border: 1px solid #c2c5cd; z-index: 10; position: absolute; display: none; border-top: none;">
<div data-toggle="modal" data-target="#modal-add-credito" id="add-credito-btn" data-id-jogador="{{ $deleted_players->id }}" style="text-align: center; line-height: 30px; cursor: pointer;">Transferir Dinheiro</div>
<div data-toggle="modal" data-target="#modal-update-senha" id="change-pwd-btn" data-id-jogador="{{ $deleted_players->id }}" style="text-align: center; line-height: 30px; cursor: pointer;">Mudar Senha</div>
</div>
Foreach
<div class="content">
<div class="table-responsive alt-table">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th data-sort="int" class="table-check">
ID do Jogador
</th>
<th data-sort="string">
Nome do Jogador
</th>
<th data-sort="string">
Data
</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
@if (count($players_deleted) > 0)
@foreach($players_deleted as $deleted_players)
<tr>
<td class="table-check">
{{ $deleted_players->id }}
</td>
<td class="table-check">
{{ $deleted_players->username }}
</td>
<td class="table-check">
{{ $deleted_players->created_at }}
</td>
<td class="table-check">
<div id="show_jogadores" style="width: 150px; height: 30px; border: 1px solid #c2c5cd; text-align: center; line-height: 28px; float: left; border-right: none; cursor: pointer;">
<p>Escolha uma opção</p>
</div>
<div style="width: 30px; height: 30px; border: 1px solid #c2c5cd; text-align: center; line-height: 28px; float: left; cursor: pointer;">
<i id="botao_ver_opcoes" data-id-jogador="{{ $deleted_players->id }}" class="fa fa-angle-down" aria-hidden="true"></i>
</div>
<div id="opcoes-{{ $deleted_players->id }}" style="width: 180px; margin-top: 30px; background-color: white; border: 1px solid #c2c5cd; z-index: 10; position: absolute; display: none; border-top: none;">
<div data-toggle="modal" data-target="#modal-add-credito" id="add-credito-btn" data-id-jogador="{{ $deleted_players->id }}" style="text-align: center; line-height: 30px; cursor: pointer;">Transferir Dinheiro</div>
<div data-toggle="modal" data-target="#modal-update-senha" id="change-pwd-btn" data-id-jogador="{{ $deleted_players->id }}" style="text-align: center; line-height: 30px; cursor: pointer;">Mudar Senha</div>
</div>
</td>
</tr>
@endforeach
</tbody>
@else
<tbody>
<tr>
<th colspan="4" class="table-check">
<div style="text-align: center; color: #000000;">Nenhum Jogador eliminado encontrado</div>
</th>
</tr>
</tbody>
@endif
</table>
</div>
</div>