#My hamburger menu is randomly breaking and i dont know why.

9 messages · Page 1 of 1 (latest)

tepid raft
#

very weird

chrome dagger
#
  1. Have you checked via the Inspector that the classes are being toggled correctly?

  2. Your JS is targeting “.nav-links” which I don’t see in your HTML. Maybe you meant “.nav-link” (singular, not plural)?

Also, not sure if you need to worry about removing the “active” class when clicking on a “.nav-link” since the page would refresh on navigation anyway.

trim marsh
#

still broken. Also the hamburger menu is working fine when using npm run dev. And the classes do toggle active

chrome dagger
#

Are you able to share the site?

#

And just to check, you used the inspector on the live site to check the classes?

shut briar
#

Is this a hydration issue? Your JS saves off elements into local variables. If your elements are re-rendering client-side, they may replace the elements during hydration. Your saved-off query selectors would then be pointing to elements that are no longer in the document tree

If so, the standard fix is to use event delegation. Capture the toggle event at document and check to see if the target matches the selector you want.

chrome dagger
#

If you're using Git, you can go back in your history and find where it still worked then compare that commit with the next one that broke it

faint scroll
#

a minimal reproduction github repo would be needed here for a meaningful analysis