Created
January 17, 2016 17:25
-
-
Save grappler/c4c0468d3cdbf4b276e9 to your computer and use it in GitHub Desktop.
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
document.addEventListener('DOMContentLoaded', function(){ | |
var tabs = { | |
tab1: document.getElementById('tab-link-1'), | |
tab2: document.getElementById('tab-link-2'), | |
tab3: document.getElementById('tab-link-3'), | |
tab4: document.getElementById('tab-link-4') | |
} | |
var content = { | |
one: document.getElementById("tab-content-1"), | |
two: document.getElementById("tab-content-2"), | |
three: document.getElementById("tab-content-3"), | |
four: document.getElementById("tab-content-4") | |
} | |
for (tab in tabs) { | |
if(tabs[tab]) { | |
tabs[tab].addEventListener('click', function(event) { | |
event.preventDefault(); | |
var $this = this; | |
clearSelected(); | |
$this.classList.add("selected"); | |
clearActive(); | |
if ($this.id === "tab-link-1") { | |
content.one.classList.add("active"); | |
} else if ($this.id === "tab-link-2") { | |
content.two.classList.add("active"); | |
} else if ($this.id === "tab-link-3") { | |
content.three.classList.add("active"); | |
} else { | |
content.four.classList.add("active"); | |
} | |
}); | |
} | |
} | |
var has_edd_error = document.getElementsByClassName('edd-alert'); | |
if (has_edd_error.length > 0) { | |
clearSelected(); | |
tabs.tab4.classList.add("selected"); | |
clearActive(); | |
content.four.classList.add("active"); | |
} | |
function clearSelected() { | |
for (tab in tabs) { | |
tabs[tab].classList.remove("selected"); | |
} | |
} | |
function clearActive() { | |
for (element in content) { | |
content[element].classList.remove("active"); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment