Created
June 9, 2011 15:02
-
-
Save neaf/1016902 to your computer and use it in GitHub Desktop.
Simple JS tabs
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
<div class="tabs"> | |
<ul class="tab-list"> | |
<li><a href="#tab-1">Tab 1</a></li> | |
<li><a href="#tab-2">Tab 2</a></li> | |
<li><a href="#tab-3">Tab 3</a></li> | |
</ul> <!-- .tab-list --> | |
<div class="tab" id="tab-1"></div> | |
<div class="tab" id="tab-2"></div> | |
<div class="tab" id="tab-3"></div> | |
</div> <!-- .tabs --> |
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
verticalTabs: function() { | |
$('.tabs').each(function() { | |
var $el = $(this); | |
var $tabs = $el.find('.tab'); | |
var $links = $el.find('.tab-list a'); | |
$tabs.hide(); | |
function activate(el) { | |
var $link = $(el); | |
$links.removeClass('active'); | |
$tabs.hide(); | |
$link.addClass('active'); | |
$($link.attr('href')).show(); | |
} | |
$links.bind('click', function() { activate(this); }); | |
activate($links[0]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment