jQuery Twitter Bootstrap Tab select

jquery, tabs, twitter-bootstrap

Solution

Instead of calling `.tab('show')` on the `div` you want to be visible, try doing it on the `a` element that you would use to activate it:

$('a[href="#cart-data-tab"]').tab('show');

Or probably better yet, just do it by id:

$('#cart-data-btn').tab('show');

Problem

I've been looking around the net and tried many examples but can't figure out why I can't show a specific tab thru jQuery. This is my tab html: ``` <ul class="nav nav-tabs nav-inside-tabs" id="cartTabs"> <li class="active"><a href="#cart-tab" data-toggle="tab" class="cart-btn">Purchases</a></li> <li><a href="#cart-data-tab" data-toggle="tab" id="cart-data-btn" class="cart-btn">Data</a></li> <li><a href="#cart-pay-tab" data-toggle="tab" id="cart-pay-btn" class="cart-btn">Pay</a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="cart-tab"> Cart </div> <div class="tab-pane" id="cart-data-tab"> Content data </div> <div class="tab-pane" id="cart-pay-tab"> Content pay </div> </div> ``` I tried a switch and the alert show up good, but doesn't activate the correct tab: ``` $('#cart-goon-btn').click(function(e){ e.preventDefault(); if(!$(this).attr('disabled')){ var current_tab = $('.tab-pane.active').attr('id'); switch(current_tab){ case 'cart-tab': $('#cartTabs li a').eq($('#cart-data-tab')).tab('show'); alertify.alert('1') break; case 'cart-data-tab': //cart-pay-tab alertify.alert('2') break; case 'cart-pay-tab': //checkout break; } } }); ``` Any hint?

Original source