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 Collapse 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> <script> $(document).ready(function(){ $("#myCollapsible").on('hidden.bs.collapse', function(){ alert("Collapsible element has been completely closed."); }); }); </script> <style> p{ background: #eee; border: 1px solid #ccc; margin: 20px 0; padding: 30px; } </style> </head> <body> <div class="container-lg my-3"> <!-- Trigger Button HTML --> <input type="button" class="btn btn-primary" data-toggle="collapse" data-target="#myCollapsible" value="Toggle Button"> <!-- Collapsible Element HTML --> <div id="myCollapsible" class="collapse show"><p>This is a simple example of expanding and collapsing individual element via data attribute. <br>Click on the <b>Toggle Button</b> button to see the effect.</p></div> </div> </body> </html>