0
I have a div
that by default this hidden, I have a simple jquery that when I click on the button opens the div, only I have several buttons with the same hidden div.
What happens is if I open a div when I click another button, it opens the same div and they’re all open. What I want is that when clicked 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>
You only have one ID
#botao_ver_opcoes
on the page or you have one for each player. Can you show the HTML that is generated for each player? (if that’s what you put in the question, there’s a parent element of those two per player?)– Sergio
A foreach is generated in which each one has the id #botao_ver_options
– César Sousa
Okay, you can show that
forEach
? it must be corrected.– Sergio
This in the question
– César Sousa
I will be obliged to insist on my old suggestion: please use scores in your texts. They are not merely decorative, but make the text much easier to read, as it makes sense.
– Woss
Can you display the HTML you have rendered? without these
{{...}}
...– Sergio