Anchor link in Dawn Theme won't close mobile menu

Topic summary

A user is experiencing an issue where the mobile menu in Shopify’s Dawn theme remains stuck open after clicking an anchor link, preventing users from seeing the exit icon without scrolling up.

Problem Details:

  • Initial jQuery code attempted to close the menu by triggering a click on .burger-container but failed
  • The issue occurs specifically with anchor links (e.g., #roadmap) in the mobile navigation
  • Users cannot easily close the menu once navigated to the anchor section

Proposed Solutions:

  1. One contributor suggested adding a jQuery library script before </head> in theme.liquid, but this didn’t resolve the issue
  2. Another user shared a working workaround for Dawn 9.0:
    • Add custom jQuery code in header.liquid (near localization-form.js)
    • The code simulates a click on the header menu icon when an anchor link is clicked
    • Must duplicate the script for each anchor link in the menu
    • Caveat: This is a temporary hack that may break if Dawn’s header structure changes

Current Status:
The discussion remains open with one user asking for clarification on implementation, as they cannot locate localization-form.js in their header.liquid file.

Summarized with AI on November 16. AI used: claude-sonnet-4-5-20250929.

Hi everyone,

I am wondering if there are coding alternatives for closing a mobile menu after an anchor link is selected in the menu? I’ve tried the following code in my theme editor js but alas no luck:

$(function () {
$(‘.mobile-menu__item [href*=“https://jd6602741.myshopify.com/#roadmap”]’).on(‘click’, function () {
$(‘.burger-container’).trigger(‘click’);
});
});

Image below shows that the top bar is moved up, users can’t scroll up to see the menu exit icon, users are stuck on this screen.

I’m wondering if there is a better functioning code, or a code for users to tap out of the menu to close the menu since the menu is stuck open when navigated to the anchor link section. Or, if there’s a code that sets the duration of time that the mobile menu is open for.

All answers welcome.

Thanks in advance!

1 Like

Oh Also - this is for the Dawn theme if that matters

@Morb1rd

Sorry you are facing this issue, it would be my pleasure to help you.

Welcome to the Shopify community! :blush:
Thanks for your good question.

Please share your site URL,
I will check out the issue and provide you a solution here.

Hi @KetanKumar

Thank you for reaching out.

Here is my link, it’s a test website: https://jd6602741.myshopify.com/

My password for website viewing: praust

Thank you!

@Morb1rd

can you add this before this

Hello @KetanKumar ,

I’m sorry, but where do I find this script? Thank you.

Hello @KetanKumar ,

I’ve searched for “ajax” throughout my layout, templates, sections, snippets, assets, config, and locals - I could not find the script link mentioned above. Do I need to implement it somewhere?

Here’s an image of my theme editor js

Thank you

1 Like

@Morb1rd

add script theme.liquide before

Hi @KetanKumar ,

Thanks for the response, unfortunately that has not changed. Here is were I placed the script.

1 Like

@Morb1rd

oh sorry if doesn’t work so it can be done some customization code

Hi! I was facing the same problem with Dawn version 9.0 and I figured out a solution for it. It’s a hacky temporary one, but it works.

In case anybody has the same problem, follow these steps.

  1. Customize theme code and go to Sections > header.liquid
  2. Find “localization-form.js” and under the endif tags (or could be anywhere before the header tag), insert this code
  1. Change the uppercased link in the code after the href tag to the hash link you have set, for example - https://exampledomain.net/#contact-form

Note that you have to duplicate this code inside the script tag for every hash link you have. Sorry I cannot optimize since I don’t have the time for it.

$(function () {
  $('.menu-drawer__menu-item[href="https://CHANGETOYOURDOMAIN.TLD/#CHANGETOYOURSECONDHASH"]').on('click', function () {
    $('.header__icon--menu').click();
  });
});

Also note that this might not work if Dawn decides to change how they code their header.

In case there are devs here who would like to troubleshoot, the Jquery logic is

  1. Select the hash link

  2. On click, find and select the header icon/element that is tied to the opening and closing of the menu

  3. Simulate a click to that element

1 Like

Hi,

Having the similar issue. Could you please tell me where to put those code? In the header.liquid there is no localization-form.js.