Skip to content
Advertisement

jQuery anchor links toggling a menu?

I used jQuery to make a toggle menu where someone can click on different span titles to toggle between different containers of content (on the website, this toggle menu toggles between different contact forms). The menu works, but I am trying to make it so that if a user clicks an anchor link on a different page, they will be sent to this page and the menu will automatically toggle to the corresponding container of content.

For example, if someone were to click on an anchor link like “mydomain.com/test-page/#third”, I would want the content from the third menu item to toggle and show automatically when the page loads. I have been playing around with using “window.location.hash” to trigger a click event like this, but can’t figure it out.

Is there a way to trigger a click event when the page url has a certain anchor hash like this at the end of it?

Would really appreciate any help folks can offer!

Here is the fiddle: https://jsfiddle.net/ecv5jwsr/

JavaScript
JavaScript

Advertisement

Answer

To do this you need to set tab id and save it in url as parameter like this:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement