Created
July 6, 2011 20:52
-
-
Save inlikealion/1068298 to your computer and use it in GitHub Desktop.
Simply tabs.
This file contains 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
$(function() { | |
// Functionality: | |
// ID tabs like this: | |
// [TAB_PREFIX][name_1] | |
// [TAB_PREFIX][name_2] | |
// [TAB_PREFIX][name_3] | |
// ID tab content like this: | |
// [CONTENT_PREFIX][name_1] | |
// [CONTENT_PREFIX][name_2] | |
// [CONTENT_PREFIX][name_3] | |
var ACTIVE_CLASS = "active"; | |
var TAB_PREFIX = "tab_button_"; | |
var CONTENT_PREFIX = "tab_content_"; | |
var TAB_ELEMENT = "li"; | |
var CONTENT_ELEMENT = "li"; | |
var $tabs = $(TAB_ELEMENT + "[id^=" + TAB_PREFIX + "]"); | |
var $currentTab = $tabs.eq(0).addClass(ACTIVE_CLASS); | |
var $currentContent = $(CONTENT_ELEMENT + "[id^=" + CONTENT_PREFIX + "]").eq(0).show().addClass(ACTIVE_CLASS); | |
$tabs.click( | |
function(event) { | |
event.preventDefault(); | |
clickedTab = this.id.substr(TAB_PREFIX.length); | |
$currentTab.removeClass(ACTIVE_CLASS); | |
$currentContent.hide().removeClass(ACTIVE_CLASS); | |
$currentTab = $(this).addClass(ACTIVE_CLASS); | |
$currentContent = $("#" + CONTENT_PREFIX + clickedTab).show().addClass(ACTIVE_CLASS); | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment