Any code added to button onClick breaks default behavior

Hi, I’m running into a persistent issue with a Wix button.

Every time I add code using $w('#myButton').onClick(() => { ... }), the button’s default behavior stops working — even if I don’t override anything in the function. For example, even this simple handler breaks the link:

$w.onReady(() => {
  $w('#whatsappButton').onClick(() => {
    console.log('clicked');
  });
});

The button is set (in the editor) to open an external WhatsApp link in a new tab. But once the code runs, the link no longer opens. I’ve tried using wixWindow.openExternalLink(), window.open(), and even just letting Wix handle it — but once .onClick() is present, the navigation is blocked.

Even worse, window and dataLayer are undefined in this context, so I can’t send events to Google Tag Manager either.

Is this expected behavior? Or is this a known bug in how buttons behave in Wix when code is attached?

Thanks!

Hi, @ONLN_Digital_Marketi !!

It’s possible that the event assigned to the button in the editor is being overridden by the .onClick() handler in the code. I tested it on my end as well and saw the same result. :innocent:

Yes, any onclick event in the code panel will overwrite any onclick event added in the editor. That makes sense to me.

The only issue I’m still facing is that when I manually add code to the button (using .onClick() in Velo), the button stops working entirely — it no longer redirects or responds. So even though I understand that adding code overrides the default behavior, the custom code itself doesn’t function either.

Any idea what might be causing this?

If you need the onClick, I’d recommend removing the link, and then using wixLocationFronted - To | Velo - to navigate to the page/place you want after doing any other things that need doing before :slight_smile:

1 Like