1
I want to show/hide the div by clicking on it and hide by clicking on another item, I am only able to hide by clicking on another item, by clicking on it I am not able to hide.
Example of how the code is
$(document).on('click', '.opener', function() {
let posicao = $(this).index(".opener");
$('.level0.nav-submenu.nav-panel--dropdown.nav-panel').hide();
if ($('.nav-item.level0.nav-' + (posicao+1) + ' ul').is(':visible')) {
$('.nav-item.level0.nav-' + (posicao+1) + ' ul').hide();
} else {
$('.nav-item.level0.nav-' + (posicao+1) + ' ul').show();
}
});
.opener {
cursor:pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav id="mainmenu" class="navi opt-fx-fade-inout opt-sb0 opt-sob opt-hide480 centered with-bullets nav-mobile acco nav-mobile-triggerable">
<ul>
<li class="nav-item level0 nav-1">
<span>Datas Especiais</span>
<span class="opener">\/</span>
<ul class="level0 nav-submenu nav-panel--dropdown nav-panel" style="display: none;">
<li class="nav-item classic">
<span>teste1</span></li></ul></li>
<li class="nav-item level0 nav-2">
<span>Ocasiões</span>
<span class="opener">\/</span>
<ul class="level0 nav-submenu nav-panel--dropdown nav-panel" style="display: none;">
<li class="nav-item classic">
<span>teste2</span></li></ul></li>
<li class="nav-item level0 nav-3">
<span>Categorias</span>
<span class="opener">\/</span>
<ul class="level0 nav-submenu nav-panel--dropdown nav-panel" style="display: none;">
<li class="nav-item classic">
<span>test3</span></li></ul></li>
<li class="nav-item level0 nav-4">
<span>Flores</span>
<span class="opener">\/</span>
<ul class="level0 nav-submenu nav-panel--dropdown nav-panel" style="display: none;">
<li class="nav-item classic">
<span>teste4</span></li></ul></li>
</ul>
</nav>
the question to me is a little confused, I do not know if others agree, but would consider editing and inserting part of the code within the question.
– WMomesso
I edited the question and made it simpler, I think you better understand, running the code I put I think gives to have a notion.
– Gustavo Souza
@Wagnerfernandomomesso The code is already in the executable, I would like me to put it again?
– Gustavo Souza