javascriptbootstrap-4bootstrap-tabs

Bootstrap tabs not working the first time


I am trying to implement two basic tabs and panels. The panel does not show the content(Page 1) on page load. However, clicking on the other tab works fine with the right content(Page 2) and then going back to the first tab works fine(Page 1).

<ul class="nav nav-tabs">
    <li class="active"><a href="#panel1" data-toggle="tab">Page 1</a></li>
    <li><a href="#panel2" data-toggle="tab">Page 2</a></li>
</ul>

<div class="tab-content">
    <div id="panel1" class="tab-pane">
        Page 1
    </div>
    <div id="panel2" class="tab-pane">
        Page 2
    </div>
</div>

Is there something I am missing?


Solution

  • You don't have the active class for the content panel. You need the following to show the panel1 content by default:

    <div id="panel1" class="tab-pane show active">...