Mobile Menu Not Closing When Using Anchor Links

Hi, i am currently using anchor links for my header menu and it works fine on desktop. However, on mobile, clicking on any of the anchor links does not close the menu. Is there a way to close the menu after clicking on my anchor links?

I am currently on the Publisher theme.

https://38550a-2.myshopify.com/

pw: ov24

You can try to add this code to your Online store > Themes > Edit code > open theme.liquid file, add code before and check if it works

document.addEventListener('DOMContentLoaded', function () {
  const newsletterLinks = document.querySelectorAll('.menu-drawer__menu-item');
  
  newsletterLinks.forEach(function (link) {
    link.addEventListener('click', function () {
      document.querySelector('#Details-menu-drawer-container span').click();
    });
  });
});

Hi Dan,

Appreciate you trying to help. I have inserted the code before but it still does not work. Nothing seems to have changed.

Please try to update code to this and check again


2 Likes

Works like a charm! Thanks Dan!

Happy I could help :grin:

Worked great in 2025 with Sense theme, thank you!!

1 Like

You are very welcome!