HTML CSS examples for Bootstrap:Tab
These are the standard Bootstrap events to enhance the tab functionality.
Event | Description |
---|---|
show.bs.tab | fires on tab show, but before the new tab has been shown. |
shown.bs.tab | fires on tab show after a tab has been shown. |
hide.bs.tab | fires when the current active tab is to be hidden and thus a new tab is to be shown. |
hidden.bs.tab | fires after the previous active tab is hidden and a new tab is shown. |
The following example displays the names of active tab and previous tab to the user when transition of a tab has been fully completed.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Example of Bootstrap 3 Tabs Events</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('a[data-toggle="tab"]').on('shown.bs.tab', function(e){ var activeTab = $(e.target).text(); // Get the name of active tab var previousTab = $(e.relatedTarget).text(); // Get the name of previous tab $(".active-tab span").html(activeTab); $(".previous-tab span").html(previousTab); });<!--from w ww .j a va 2 s .c om--> }); </script> </head> <body> <div> <ul class="nav nav-tabs" id="myTab"> <li class="active"><a data-toggle="tab" href="#home">Home</a></li> <li><a data-toggle="tab" href="#profile">HTML</a></li> <li class="dropdown"> <a data-toggle="dropdown" class="dropdown-toggle" href="#">Dropdown <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a data-toggle="tab" href="#dropdown1">Dropdown1</a></li> <li><a data-toggle="tab" href="#dropdown2">Dropdown2</a></li> </ul> </li> </ul> <div class="tab-content" id="myTabContent"> <div id="sectionA" class="tab-pane fade in active"> <h3>Section A</h3> <p>Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui. Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth.</p> </div> <div id="sectionB" class="tab-pane fade"> <h3>Section B</h3> <p>Vestibulum nec erat eu nulla rhoncus fringilla ut non neque. Vivamus nibh urna, ornare id gravida ut, mollis a magna. Aliquam porttitor condimentum nisi, eu viverra ipsum porta ut. Nam hendrerit bibendum turpis, sed molestie mi fermentum id. Aenean volutpat velit sem. Sed consequat ante in rutrum convallis. Nunc facilisis leo at faucibus adipiscing.</p> </div> <div id="dropdown1" class="tab-pane fade"> <h3>Dropdown 1</h3> <p>WInteger convallis, nulla in sollicitudin placerat, ligula enim auctor lectus, in mollis diam dolor at lorem. Sed bibendum nibh sit amet dictum feugiat. Vivamus arcu sem, cursus a feugiat ut, iaculis at erat. Donec vehicula at ligula vitae venenatis. Sed nunc nulla, vehicula non porttitor in, pharetra et dolor. Fusce nec velit velit. Pellentesque consectetur eros.</p> </div> <div id="dropdown2" class="tab-pane fade"> <h3>Dropdown 2</h3> <p>Donec vel placerat quam, ut euismod risus. Sed a mi suscipit, elementum sem a, hendrerit velit. Donec at erat magna. Sed dignissim orci nec eleifend egestas. Donec eget mi consequat massa vestibulum laoreet. Mauris et ultrices nulla, malesuada volutpat ante. Fusce ut orci lorem. Donec molestie libero in tempus imperdiet. Cum sociis natoque penatibus et magnis dis parturient.</p> </div> </div> <hr> <p class="active-tab"><strong>Active Tab</strong>: <span></span></p> <p class="previous-tab"><strong>Previous Tab</strong>: <span></span></p> </div> </body> </html>