Hamburger menu auto close

Hello everyone. I have a hamburger menu on a page when in mobile version. Quick question is how can i make it to auto close after click. Thanks in advance.

Hello @MrPrice there you have an option, that or when you click a link or click outside the menu it will close the toggle menu:

  1. Go to Page Settings:

image

  1. Go to the tab code:

image

  1. Select the option Footer:

image

  1. Add the following code:
<script>
$(document).on('click', function() {
  return $('.collapse').collapse('hide');
});
</script>

Hope it helps you…

There you have your site working:

Kapture 2021-07-28 at 00.02.24.mp4.zip (3.0 MB)

1 Like

Unless it’s Bootstrap 5.

@Pealco we have to start dropping JQuery. So hard aye.

Thanks so much! @Pealco Going to add the code to various sites Ive done! :slight_smile:

Hello @PeteSharp in case of BS5 I have a different approach:

In the menu items I add two Custom Attributes, like this, for who needs:

1st - Click in the list:
image

2nd - In the custom Attributes:
image

3rd - Add the following ones:

Name: data-bs-toggle
Value: collapse

And

Name: data-bs-target
Value: .navbar-collapse.show (dont forget both dot)

And voila:

Kapture 2021-07-28 at 21.54.27

Hope it helps …