How to close the mobile navbar after clicking

Related searches

I'm making a website and need some help with the navbar for a mobile device. Basicly I want to close the nav when clicked for example "Destaques". All i need to do is remove the class "opened" when I clicked at any link. since it's only one page, it never redirects to any other page.

I've tried to change with the function .click and getElement by Id but didnt work, so I click on <a> but want to change the class for <nav> from <nav class="nav1 opened" to <nav class="nav1" Here's an example of my code.

<nav class="nav1" id="nav-mobile">
    <a class="mobile_menu_close"></a>
        <div class="container">
            <div class="flex">
                 <ul class="nav1_links">
                        <li class="links-header"><a href="#contact"> Contact</a></li>

Does anyone have a solution for this, I've tried probably 20 diferent ways but haven't found a awnser.


I have set up some code for you that will add/remove .open class. All in regular JS. This can be applied to your hamburger icon instead of the button for the open click event and each <li> for the close event.

The Fiddle

Auto close Navbar when click on link (responsive mode), HelloOn the navigation bar - responsive mode - when I click on a link (case linding page), the navigation bar does not close automatically !!Is there a way to� on a small screen you expand the navbar by clicking on the "hamburger-button". after you click on a nav-link (here for example "Karte"), the navbar doesn't go back to its previous state, its still expanded. You have to click on the "hamburger-button" again to get some more space on the screen.

That won't happen because when you click on <a> tags that contains href Attribute, page will refresh and JavaScript Codes won't work you should use a "close button" using<button> tag instead of <a> tags

nav collapse on click (hide mobile menu after click on menu , If you have scrolling navbar, in mobile view the only way to close it is clicking menu button. It doesn't collapse after menu item click. To solve it, use following� Topic: nav collapse on click (hide mobile menu after click on menu item) Nikita Sarbashev pro asked 4 years ago 0 0 If you have scrolling navbar, in mobile view the only way to close it is clicking menu button.

Try this


Bootstrap 4 Close Mobile Menu After Click on Codeply, Method using jQuery $('.navbar-collapse').collapse('hide') to close the Navbar links after click. Codeply example. Hello readers, I am writing a code for the Bootstrap-4 navbar collapse menu close when clicking outside of the navigation bar on mobile. I wrote HTML here for navigation bar and javascript for the close collapsing menu when we click outside the navbar into mobile. I used bootstrap-4 library and jquery. To see the result click outside of the navbar.

If you use jQuery you could do this

$( ".nav1" ).removeClass("opened");

Close mobile menu on click, I need the mobile menu to close after a link has been clicked. I have a one page site with #anchors in the nav. Because the toggle menu doesn't close once a link � After trying another search here, I was able find something that worked. I just needed to know which class to work with to get this done for Bootstrap 4. $('.navbar-nav>li>a').on('click', function(){ $('.navbar-collapse').collapse('hide'); }); How to hide collapsible Bootstrap 4 navbar on click

Close mobile bootstrap menu after click, <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">. 7. <span class="sr-only">Toggle navigation</span>. 8. Hello Uriel, unfortunately there's no solution for this issue. It happens because the menu closes when page is reloaded. But with one page design the page is not reloaded when you're navigating between anchors.

When the navbar is collapsed clicking on a dropdown works and the dropdown closes. If the navbar is not collapsed clicking on the dropdown menu items works but the menu does not closes. Of I put a click event listener (click)="hideNavbar (navbar)", it closes it and then it reopens by itself. It used to work until a day or two ago.

How to close toggle overlay menu when clicking navigation item anchor link? Hi guys So, I have a one-page layout with several sections, and its respective anchors are in the menu as items pointing out to those sections down that same page.

  • the only error on you code the getElementById, on my code didn't reach the Id with that, but if you put ´´$("#yourId").removeClass("yourClass"); e.preventDefault() /*ignores actual link*/´´ It works just fine.
  • but my page doesnt refresh, it just goes to the id of a ´<a>´ with the name of the href