Skip to content

Instantly share code, notes, and snippets.

@Koc
Created November 17, 2010 12:37
Show Gist options
  • Save Koc/703344 to your computer and use it in GitHub Desktop.
Save Koc/703344 to your computer and use it in GitHub Desktop.
function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!this.hasClass(ele,cls))
ele.className += " "+cls;
}
function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}
}
var tabs = ['tab-block1','tab-block2','tab-block3'];
function hide() {
for (i in tabs) {
document.getElementById(tabs[i]).style.display='none';
removeClass(document.getElementById('tabs-handlers').childred[i], 'active');
removeClass(document.getElementById(tabs[i]), 'active');
}
}
function show(id) {
hide();
document.getElementById(id).style.display='block';
addClass(document.getElementById('tabs-handlers').childred[tabs.indexOf(id)], 'active');
addClass(document.getElementById(id), 'active');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment