> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: changeState(stateReference: any)

# Method package: w

# Method menu location: w --> MultiStateBox --> changeState

# Method Link: https://dev.wix.com/docs/velo/velo-only-apis/$w/multi-state-box/change-state.md

# Method Description:

Change the multi-state box's current state to a specific state.

The `changeState()` function returns a Promise that is resolved when
 the multi-state box finishes moving from the current state to the state
 referred to by `stateReference`. `stateReference` can be a state object or
 a state [`id`](https://dev.wix.com/docs/velo/velo-only-apis/$w/state/id.md).

 You can retrieve [`State`](https://dev.wix.com/docs/velo/velo-only-apis/$w/state/introduction.md) objects to pass to the
 `stateReference` parameter from your multi-state box using the
 [`currentState`](#currentState) or [`states`](#states) properties.
 
 > **Note:**  
 > If you call `changeState()` on a child multi-state box, it doesn't run until the parent box moves to the state where the child box is displayed.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Move to a new state using an id

```javascript
$w("#myStatebox").changeState("state2");
```

## Move to a new state using a [`State`](https://dev.wix.com/docs/velo/velo-only-apis/$w/state/introduction.md) object

```javascript
$w("#myStatebox").changeState(state);

```

## Move to a new state and log a message when the move is finished

```javascript
$w("#myStatebox").changeState("state2")
  .then( (newState) => {
    console.log(`Done moving to ${newState.id}`);
  } );
```

## Switch between 2 states

```javascript
$w("#buttonState1").onClick(() => {
  $w('#myStatebox').changeState("state2");
} );

$w("#buttonState2").onClick(() => {
  $w('#myStatebox').changeState("state1");
} );

```

## Switch between 3 states

```javascript
$w.onReady(() => {
  $w('#newYorkButton').onClick(() => {
    $w('#statebox').changeState('newYork');
  });

  $w('#texasButton').onClick(() => {
    $w('#statebox').changeState('texas');
  });

  $w('#californiaButton').onClick(() => {
    $w('#statebox').changeState('california');
  });
});

```

## State per Status

```javascript
wixLocationFrontend.onChange(() => {
  // Get all info on the current product
  $w('#myProductPage').getProduct()
    .then( (product) => {
      if (!product.inStock) {
        $w('#badgeStatebox').changeState("outOfStock");
      }
      // If the price is different than the discount price, indicating a sale
      else if (product.price !== product.discountedPrice) {
        $w('#badgeStatebox').changeState("onSale");
      }
      else {
        $w('#badgeStatebox').changeState("checkMeOut");
      }
    } )
    .catch( (error) => {
      console.log(error);
    } );
} );

```

## Focus on the button element in a multi-state box after switching states

```javascript
  $w("#buttonState1").onClick(() => {
    $w("#myStateBox").changeState("state2");
	  $w("#buttonState2").focus()
  });
  $w("#buttonState2").onClick(() => {
    $w("#myStateBox").changeState("state1");
	  $w("#buttonState1").focus()
  });
```

---