Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap 4 Tabs Events</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script> <style> .bs-example{ margin: 20px; } </style> <script> $(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); }); }); </script> </head> <body> <div class="bs-example"> <ul id="myTab" class="nav nav-tabs"> <li class="nav-item"> <a href="#home" class="nav-link active" data-toggle="tab">Home</a> </li> <li class="nav-item"> <a href="#profile" class="nav-link" data-toggle="tab">Profile</a> </li> <li class="nav-item"> <a href="#messages" class="nav-link" data-toggle="tab">Messages</a> </li> </ul> <div class="tab-content"> <div class="tab-pane fade show active" id="home"> <h4 class="mt-2">Home tab content</h4> <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 class="tab-pane fade" id="profile"> <h4 class="mt-2">Profile tab content</h4> <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 class="tab-pane fade" id="messages"> <h4 class="mt-2">Messages tab content</h4> <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.</p> </div> </div> <hr> <p class="text-info"><em>Click on any other tab to see how it works.</em></p> <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>