Created
November 7, 2012 06:42
-
-
Save djs070/4029875 to your computer and use it in GitHub Desktop.
jQuery tabs script
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
// Define elements | |
var $tabContainer = $('.tab-container'); | |
var tabContentClass = '.tab-content'; | |
var tabHeadingClass = '.tab-heading'; | |
// Hide all tab content | |
$tabContainer.find(tabContentClass).hide(); | |
// When tab button is clicked... | |
$tabContainer.find(tabHeadingClass).click(function(){ | |
// Remove styling class | |
$(tabHeadingClass).removeClass('active'); | |
// Hide all tabs | |
$tabContainer.find(tabContentClass).hide(); | |
// Set active styling class on the clicked heading, and show the tab whose | |
// selector is contained in the heading's data-fortab attribute | |
$($(this).addClass('active').attr('data-fortab')).show(); | |
}); | |
// Activate the first tab by default | |
$tabContainer.find(tabHeadingClass).first().click(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment