.nav-tabs tab events are based on .nav-tabs and not on .tab-content elements. Therefore, to #tab1 show event, you need an element with href that is directed to #tab1 , not the content element #tab1 .
So instead:
$('#tab1').on('shown.bs.tab', function (e) { alert("tab1"); });
Do this instead:
$('[href=#tab1]').on('shown.bs.tab', function (e) { alert("tab1"); });
Or, to capture all of them, simply do the following:
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { alert(e.target.href); })
Demonstration in fragments of the stack
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { alert(e.target.href); })
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script> <div role="tabpanel"> <ul class="nav nav-tabs" role="tablist"> <li class="active"><a id="tab1" href="#chart1" role="tab" data-toggle="tab">Tab 1</a></li> <li><a id="tab2" href="#chart2" role="tab" data-toggle="tab">Tab 2</a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="chart1">Tab 1 Content</div> <div class="tab-pane" id="chart2">Tabe 2 Content</div> </div> </div>
source share