Auto Close Expanded Navbar Dropdown on Menu Item Selection

So I have a nice little navbar which goes to a hamburger when my site in on a mobile device.

The only annoying thing is when you are on mobile and select an option on the (now dropdown) menu, you have to make another click on the hamburger to make the dropdown menu close again.

Is there a way to make it autoclose when a menu item is selected?

Code is below!

Best wishes,
Antony.

<nav class="px-0 nav_words_navbar navbar navbar-dark navbar-expand-md" id="n_nav_words">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#b_nav_words" aria-controls="collapse1" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div id="b_nav_words" class="collapse navbar-collapse">
    <img src="images/angel_white.png" width="20" height="20" id="nav_angel" class="img-fluid d-none d-xl-inline">
    <div class="navbar-nav w-100 justify-content-around">
      <a class="nav_words_item nav-item nav-link" href="#" id="a_nav_main_contacts"...

Thank you for the ``` @Teodor!

Please check:

Also, please don’t wrap each line of the code in single backticks, but use three backticks to wrap the whole code.

Works like a dream @Teodor

Thank you sooooo much for all your help, and the speed with which you answer things. I really appreciate it! :slight_smile:

1 Like