Last active
October 12, 2023 19:37
-
-
Save jasoncartwright/fb200537593638ba27900892ed9be47a to your computer and use it in GitHub Desktop.
Dead Simple Bulma Tab Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function changetab(section) { | |
document.querySelectorAll(".tabs li").forEach(item => { | |
item.classList.remove("is-active") | |
}) | |
document.querySelector("." + section).parentNode.classList.add("is-active") | |
document.querySelectorAll(".sections .column").forEach(item => { | |
item.classList.add("is-hidden") | |
}) | |
document.querySelectorAll("." + section).forEach(item => { | |
item.classList.remove("is-hidden") | |
}) | |
document.querySelector("a[data-tab='" + section + "']").parentNode.classList.add("is-active") | |
window.location.hash = section | |
return true | |
} | |
document.querySelectorAll(".tabs a").forEach(item => { | |
item.addEventListener("click", event => { | |
section = item.dataset.tab | |
changetab(section) | |
}) | |
}) | |
addEventListener("hashchange", (event) => { | |
section = window.location.hash.replace("#", "") | |
changetab(section) | |
}) | |
if (window.location.hash) { | |
window.dispatchEvent(new HashChangeEvent("hashchange")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment