Multistate Box not switching States

Hi everyone,

I’m new to coding and working on a project in Wix Studio. I’m trying to switch the state of a multistate box by clicking on icons, but it’s not working.

my Code:
$w.onReady(function () {

$w(‘#vectorImage7’).onClick(() => {

$w(‘#multiStateBox1’).changeState(“expand1”);

})

$w(‘#vectorImage8’).onClick(() => {

$w(‘#multiStateBox1’).changeState(“collapse1”);

});

Here’s what I’m experiencing:

  • In Edit mode, I can see both the collapsed and expanded states of the multistate box. But in Preview mode, clicking the icon doesn’t trigger any change – the multistate box doesn’t switch states at all. I’ve tested it on a Mac, using both Safari and Chrome, and it’s not working in either browser.

  • I also see this message in the developer console:
    “Running the code for the Impressum page. To debug this code in your browser’s dev tools, open smtka.js.”

If there’s anything I’ve missed or written incorrectly, I’d really appreciate your help!

I think you’re missing the last bracket for the onReady function. I tried using the exact code on my end and I got some other errors but that might just be a copy-paste error. Here’s the code as I adjusted it and you can see it on working on my test site under the gallery.

$w.onReady(function () {

$w('#vectorImage7').onClick(() => {
	$w('#multiStateBox1').changeState('expand1');
	});

$w('#vectorImage8').onClick(() => {
	$w('#multiStateBox1').changeState('collapse1');
	});
});
1 Like

Hi Rob,

Thank you for testing it on your end. It’s working now! I really appreciate your help and the time you took to look into it.

1 Like

I’m glad it was resolved.

Was it just the code that was wrong?

The issue was indeed caused by an error in the code.

However, after testing it again today, I realized it’s still not working as expected.

Now, when I click the icon for the first time, the state changes correctly and everything behaves as it should. But on the second click, the icon disappears entirely, and I’m no longer able to change the state again because the button is no longer visible.

Have you encountered a similar issue before? Could this possibly be related to the following console message?

Running the code for the Impressum1 page. To debug this code in your browser’s dev tools, open i85q4.js.

Could you share a link to the site and all the code you have? It’s possible that the code is collapsing the vector or might not be expanding it again when changing it.

There was something wrong with the code again, but I was able to figure it out. Thanks for your help.

2 Likes