Created
June 4, 2012 19:06
-
-
Save halfempty/2870210 to your computer and use it in GitHub Desktop.
Simple jQuery Show/Hide 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
<ul id="slidecontrols"> | |
<li><a href="#one">One</li> | |
<li><a href="#two">Two</li> | |
</ul> | |
<div id="slides"> | |
<div>This is content block One</div> | |
<div>This is content block Two</div> | |
</div> |
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
$(document).ready(function() { | |
//Set the initial state: highlight the first button... | |
$('#slidecontrols').find('li:eq(0)').addClass('selected'); | |
//and hide all slides except the first one | |
$('#slides').find('> div:eq(0)').nextAll().hide(); | |
//actions that apply on click of any of the buttons | |
$('#slidecontrols li').click( function(event) { | |
//turn off the link so it doesn't try to jump down the page | |
event.preventDefault(); | |
//un-highlight the buttons | |
$('#slidecontrols li').removeClass(); | |
//hide all the slides | |
$('#slides > div').hide(); | |
//highlight the current button | |
$(this).addClass('selected'); | |
//get the index of the current button... | |
var index = $('#slidecontrols li').index(this); | |
//and use that index to show the corresponding slide | |
$('#slides > div:eq('+index+')').show(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment