Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 Tabs Not Switching Active State Properly

I have this bit of code - just tabbed panels with separate graphs in each tabbed panel. When I switch tabs the content is not loading correctly. The active state of the panel is not changing when I click another tab, can you help a brotha figure this out?

<div class="col-sm-6">
    <!-- Tabs -->
    <ul class="nav nav-tabs" role="tablist">
        <li class="active"><a href="#DailyIncome" role="tab" data-toggle="tab">Daily Income</a></li>
        <li><a href="#YearlyIncome" role="tab" data-toggle="tab">Yearly Income</a></li>
        <li><a href="#Clients" role="tab" data-toggle="tab">Clients</a></li>
        <li><a href="#Orders" role="tab" data-toggle="tab">Orders</a></li>
    </ul>
    <!-- Content -->
    <div class="tab-content">
        <div class="tab-pane fade in active" id="DailyIncome">
            <div id="DailyIncomeChart" class="DailyIncomePanel"></div>
        </div>
        <div class="tab-pane fade" id="YearlyIncome">
            <div id="YearlyIncomeChart" class="YearlyIncomePanel"></div>
        </div>
        <div class="tab-pane fade" id="Clients"></div>
        <div class="tab-pane fade" id="Orders"></div>
    </div>
</div>
like image 507
Sabolis Avatar asked Oct 01 '14 02:10

Sabolis


1 Answers

Here's how to get it working:

  1. Add an id to the tabs <ul>, like so:

    <ul id="myTab" class="nav nav-tabs" role="tablist">

  2. Load jQuery and bootstrap js at the bottom of the page, before the </body> tag, like so:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

  3. Enable the tabs via javascript (be sure to add this below bootstrap js):

    <script> $('#myTab a').click(function (e) { e.preventDefault() $(this).tab('show') }) </script>

  4. Reload your page and it should work now.

like image 79
mariordev Avatar answered Oct 17 '22 06:10

mariordev