Site logo

Archived topic

Only open one submenu at a time (sider template)

19 replies · Started by CorpCredible on July 11, 2022

Viewing posts 16–20 of 20

Can you try this script instead?:

<script>
var parentElementLinks = document.querySelectorAll('.main-navigation .menu-item-has-children > a > .dropdown-menu-toggle');

for (var k = 0; k < parentElementLinks.length; k++) {
    parentElementLinks[k].addEventListener('click', function() {
        var _this = this;

        var openedSubMenus = _this.closest('ul').querySelectorAll('ul.toggled-on');

        if (openedSubMenus) {
            for (var o = 0; o < openedSubMenus.length; o++) {
                openedSubMenus[o].classList.remove('toggled-on');
                openedSubMenus[o].closest('li').classList.remove('sfHover');
            }
        }
    }, true);
}
</script>

Kindly let us know how it goes.

Still not working unfortunately. If I can't get the menu to work with only 1 submenu open at a time, can we look at other options? The purpose of me needing this is because when a user opens all the menu items they get cut off because of the sidebar menu height. Is there an alternate solution, besides adding a scroll bar to the side of it? Is it possible to make it so that all menu items open creates a longer page? Or is it possible to make it so that the sidebar is scrollable without a scroll bar? Or should we keep trying to make one submenu open at a time?

Can you try the code again above? I didn’t notice that the forum was stripping a portion of the code because of a probable reserve character which is why it might not be working for you. Pasted the code here as well: https://pastebin.com/hRvCH5UP.

If it doesn’t work, let me know if I can copy and paste the code directly to your site.

If that doesn’t work, we can think of a workaround.

That worked - thanks for sticking with me on this. FYI it needed to be set to wp_footer.

Yes, it needs to be hooked to wp_footer. You’re welcome Tom!

This archived topic is closed to new replies.