I'm developing a site whose menu is navbar with dropdown of bootstrap 4. When I view the site on a smaller screen, the nav is replaced by the button burger and is only "activated" when this button is clicked. However, I want it to be "disabled" when any menu item is clicked. For example, if I click on "Contact", in addition to the screen scroll to the contact part, I want the menu to go up and just the button up there.
<header>
<nav id="menu" class="navbar navbar-expand-lg">
<img id="icone" src="imgs/logoBranca.png" height="35" alt="Logo da Clara Quitutes & Cia">
<a id="nome" class="navbar-brand" href="#">Clara Quitutes & Cia</a>
<button class="navbar-toggler ml-auto custom-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav justify-content-end">
<li class="nav-item">
<a class="nav-link active" href="#inicio">Início</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Serviços</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="servicos.html#bolos">Bolos</a>
<a class="dropdown-item" href="servicos.html#salgados">Salgados</a>
<a class="dropdown-item" href="servicos.html#bebidas">Bebidas</a>
<a class="dropdown-item" href="servicos.html#docinhos">Docinhos</a>
<a class="dropdown-item" href="servicos.html#quitutes">Quitutes</a>
<a class="dropdown-item" href="servicos.html#empratados">Empratados</a>
<a class="dropdown-item" href="servicos.html#opcoes-saudaveis">Opções Saudáveis</a>
<a class="dropdown-item" href="#">Garçonete/Copeira</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#contato">Contato</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#sobre">Sobre</a>
</li>
</ul>
</div>
</nav>
</header>
I tried to use this function in JS (I found it in GitHub), but it did not work. What's wrong with the code?
//Função para o menu subir quando um item for clicado
$(document).ready(function(){
$(".navbar-nav li.-collapse a").click(function(event){
$(".navbar-collapse").collapse('hide');
});
});
Is there any other way I can do this? I'm not using jQuery in the project and would not like to use it just because it's too heavy, so preferably the solution suggestion might be developed in JS or even CSS. I want the following:
Menu without clicks
MenuwhenIclickontheburger
So,whenIclickonaniteminthelist(inthiscase,"home", "users" or "places"), the menu looks like this: