0% found this document useful (0 votes)
40 views1 page

Snippet Hash Links in Tabs Breakdance

Uploaded by

jevgen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

Snippet Hash Links in Tabs Breakdance

Uploaded by

jevgen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

function simulateClick(element) {

const clickEvent = new MouseEvent('click', { bubbles: true });


element.dispatchEvent(clickEvent);
}

const tabs = document.querySelectorAll('.bde-tabs__tab,.bde-accordion__button,.bde-


faq__question');
tabs.forEach((tab) => {
tab.addEventListener('click', () => {
const newHash = `/#${tab.id}`;
history.replaceState({}, '', newHash);
});
});

window.addEventListener('popstate', () => {
const currentHash = window.location.hash;
if (currentHash && currentHash !== '#') {
const tabId = currentHash.substring(1);
const targetTabButton = document.getElementById(tabId);
if (targetTabButton) {
simulateClick(targetTabButton);
}
}
});

const hashChangeHandler = () => {


const hash = window.location.hash.slice(1);
const targetTabButton = document.getElementById(hash);
simulateClick(targetTabButton);
};

if (window.location.hash) {
setTimeout(() => {
hashChangeHandler();
}, 0);
}

window.addEventListener('hashchange', hashChangeHandler);

You might also like