Skip to content

Instantly share code, notes, and snippets.

@jasoncartwright
Last active October 12, 2023 19:37
Show Gist options
  • Save jasoncartwright/fb200537593638ba27900892ed9be47a to your computer and use it in GitHub Desktop.
Save jasoncartwright/fb200537593638ba27900892ed9be47a to your computer and use it in GitHub Desktop.
Dead Simple Bulma Tab Javascript
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