Mobile menu onclick problem

I’m struggling with simple Velo code to receive info about what was clicked in the mobile menu in Wix Studio.

It’s the newest menu element and the menu is called menu2.

I have this in masterpage.js:

$w("#menu2").onItemClick((event) => {
     console.log(event)
});

in the desktop mode the event logs fine but not in the mobile mode. I thought part of the current menu was that this would work for all formfactors.

I tried using hamburgerMenuContent2 with onItemClick…as that is what the hamburger menu seems to be called…but I log an error without even trying to click it:

TypeError: $w(“#hamburgerMenuContent2”).onItemClick is not a function. (In ‘$w(“#hamburgerMenuContent2”).onItemClick((function(e){console.log(e)}))’,

What am I missing here???

Simon.

1 Like

Took a quick look and noticed the same thing.

I think there’s 2 things happening here:

  • Firstly, with the introduction of the unified menu, the same element ID will apply to the horizontal menu, AND to the hamburger menu button.
    • If you want to target the menu inside the hamburger menu, you’ll need to edit the menu, and select the inner menu
  • With the above said, I noticed the inner menu doesn’t currently have the same event handlers (like onItemClick) that the horizontal menu has. I’ve raised this with the team in the meantime :slight_smile:

Is there something specific you’re trying to achieve? Perhaps there’s a workaround to it :slight_smile:

Thanks for the reply Noah. Surprised nobody else has run into this yet.

What I am trying to do is rebuild the a page without having to re-download a big chunk of data from a collection - I think maybe I could force a page reload but that will cause a several second delay while the big query runs again…plus I am not sure I can actually force a reload, based on past experience (I feel like I found a way once but forget how).

The behaviour I am after is that clicking on the home button, when I’m already on the home page, should just uncollapse a bunch of sections to restore the page to it’s original state. But, if I am NOT already on the home page, I want it to go to the there as normal. So I wanted to handle the onItemClick in Velo.

I could use a separate button to achieve the same thing I guess, detaching Home from the menu and I think it could all be made to align well but really what I am doing SHOULD be possible. Very curious to hear what you get back from the team. Did you give them an example site to show the problem? I could put that together if it will help.

Simon.

Interesting! I wonder if there’s things like caching the web module request that would help with reducing having to re-run the query.

Sure did - was able to reproduce myself :slight_smile:

Woah…I have to look at this web cache thing when I am back…did not know this existed. Thanks!

1 Like