Skip to content

Instantly share code, notes, and snippets.

@evilstreak
Created December 1, 2009 09:42
Show Gist options
  • Save evilstreak/246187 to your computer and use it in GitHub Desktop.
Save evilstreak/246187 to your computer and use it in GitHub Desktop.
Simple tabs code for thinjs
$( ".tabs" ).each( function() {
// a collection of all the tabs for closing over
var tabs = [];
// find all the anchor links inside
$( "a[href^='#']", this ).each( function() {
// find the element this anchor targets and stash it
var href = this.href.substring( this.href.lastIndexOf( "#" ) ),
tab = $( href )[ 0 ];
tabs.push( tab );
// hide it
tab.style.display = "none";
// add a click event to the anchor to reveal the target
$( this ).bind( "click", function() {
$( tabs ).each( function() {
this.style.display = "none";
} );
tab.style.display = "block";
} );
} );
// see if a certain tab should be pre-selected (bash on the current hash)
if ( location.hash && $( location.hash ).length ) {
$( location.hash )[ 0 ].style.display = "block";
}
// otherwise reveal the first tab
else {
tabs[ 0 ].style.display = "block";
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment