Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Creating Dynamic Tabs in Bootstrap via JavaScript</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script> <script> document.addEventListener("DOMContentLoaded", function(){ var tabList = [].slice.call(document.querySelectorAll("#myTab a")); tabList.forEach(function(tab){ var tabTrigger = new bootstrap.Tab(tab); tab.addEventListener("click", function(event){ event.preventDefault(); tabTrigger.show(); }); }); }); </script> </head> <body> <div class="m-4"> <ul class="nav nav-pills" id="myTab"> <li class="nav-item"> <a href="#home" class="nav-link active">Home</a> </li> <li class="nav-item"> <a href="#profile" class="nav-link">Profile</a> </li> <li class="nav-item"> <a href="#messages" class="nav-link">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> </div> </body> </html>