Need JS to activate a tab page as if a user had clicked on it

Hello!

I need to programmatically change the tab of a tab container.

I have tried with

document.getElementById(‘radix-:rk:-trigger-7e1b7460-3e8c-44b7-9a03-534718066602’).dispatchEvent(new MouseEvent(‘click’, {

bubbles: true,

cancelable: true,

view: window

}));

but it didn’t work.

Any ideas to help?

Thanks!

Hi,

We use the URL “hash” property to read and store the active tab id, so by updating it you can activate any tab you need. Here is a simple JS function for you:

function activateTab(tabId) {
  window.location.hash = "#" + tabId;
}