Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Hamburger Menu close automatic by clicking Menu Item, not only by clicking Toggler "X"

kwiessner free asked 5 years ago


How can I close the Menu, by clicking for example the HOME Menu item? I need this function on an onepager.

The normal Hamburger-Menu Snippet only closes by clicking the toggler again.

The toggler itself also needs to get back in normal burger menu style when closed..

    $(document).ready(function () {
  $('.first-button').on('click', function () {
    $('.animated-icon1').toggleClass('open');
  });
});

enter image description here


kwiessner free answered 4 years ago


Hi, $('.animated-icon1').trigger('click') won't work for me. Thank you anyway!

Now I figured out how it works for me:

    $(document).ready(function() {

  $('.first-button').on('click', function () {
     // console.log('debug');
    $('.animated-icon1').toggleClass('open');
  });

  $(".nav-link").on("click", function() {
    var elem = $("#navbarSupportedContent20");

    if(elem.hasClass('show')) {
        elem.toggleClass('show');
        $('.animated-icon1').toggleClass('open');
    }
  });
});

Mateusz Łubianka staff answered 4 years ago


Hi @kaiwiessner,

Try to use this code:

$('.navbar-nav').on('click', function() {
$('.animated-icon1').trigger('click')
})

Best,



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.11.0
  • Device: Macbook Pro
  • Browser: Chrome
  • OS: Mojave
  • Provided sample code: No
  • Provided link: No