From 8b05d2bb350a6092475df23ee9d908494427d099 Mon Sep 17 00:00:00 2001 From: James Aitken Date: Wed, 8 Jun 2011 13:42:36 +0100 Subject: [PATCH] Add active class to the currently active tab content, as well as the tab itself If this is not done, then the active class remains on the tab that was initially visible on page load - even if this tab is now hidden and no longer active. This is confusing when trying to target CSS as a the selector "ul.tabs-content > li.active" , may not be visible. Also removed unused tabsContent variable. --- javascripts/app.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/javascripts/app.js b/javascripts/app.js index 5ec83da..90d46c8 100644 --- a/javascripts/app.js +++ b/javascripts/app.js @@ -12,8 +12,7 @@ $(document).ready(function() { /* Tabs Activiation ================================================== */ - var tabs = $('ul.tabs'), - tabsContent = $('ul.tabs-content'); + var tabs = $('ul.tabs'); tabs.each(function(i) { //Get all tabs @@ -32,8 +31,8 @@ $(document).ready(function() { tab.removeClass('active'); $(this).addClass('active'); - //Show Tab Content - $(contentLocation).show().siblings().hide(); + //Show Tab Content & add active class + $(contentLocation).show().addClass('active').siblings().hide().removeClass('active'); } });