Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@patrickberkeley
Created May 5, 2011 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save patrickberkeley/957331 to your computer and use it in GitHub Desktop.
Save patrickberkeley/957331 to your computer and use it in GitHub Desktop.
jQuery Tabs
$(document).ready(function(){
// Take care of the initial page load
$(".tabs-menu li:first, .tabs-content:first").addClass("active");
$(".tabs-content:not(:first)").hide();
// Capture clicks on the tabs menu. Set the clicked menu item
// to active. Show the corresponding
// content block (by index) and hide all others.
$(".tabs-menu > li > a").click(function(e){
var index = $('.tabs-menu li').index($(this).parent('li'));
$('.tabs-menu li.active, .tabs-content.active').removeClass('active');
$(this).parent('li').addClass('active');
$('.tabs-content').hide();
$('.tabs-content').eq(index).show();
return false;
});
});
%ul.tabs-menu
%li
%a{:href=>"javascript:void(0)"} First
%li
%a{:href=>"javascript:void(0)"} Second
%li
%a{:href=>"javascript:void(0)"} Third
.tabs-content
First content...
.tabs-content
Second content...
.tabs-content
Third content...
@Grawl
Copy link

Grawl commented Sep 12, 2013

simple and easy to use. thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment