Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Calling Bootstrap Dropdown Methods via jQuery</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script> <script> $(document).ready(function(){ $("#showBtn").click(function(){ $("#myDropdown").dropdown("toggle"); }); $("#hideBtn").click(function(){ $("#myDropdown").dropdown("hide"); }); $("#toggleBtn").click(function(){ $("#myDropdown").dropdown("toggle"); }); $("#updateBtn").click(function(){ $("#myDropdown").dropdown("update"); }); $("#disposeBtn").click(function(){ $("#myDropdown").dropdown("dispose"); }); }); </script> </head> <body> <div class="m-5"> <button type="button" class="btn btn-secondary" id="showBtn">Show</button> <button type="button" class="btn btn-secondary" id="hideBtn">Hide</button> <button type="button" class="btn btn-secondary" id="toggleBtn">Toggle</button> <button type="button" class="btn btn-secondary" id="updateBtn">Update</button> <button type="button" class="btn btn-danger" id="disposeBtn">Dispose</button> <hr> <div class="dropdown"> <div class="btn-group"> <button type="button" class="btn btn-primary dropdown-toggle" id="myDropdown">Dropdown</button> <div class="dropdown-menu"> <a href="#" class="dropdown-item">Action</a> <a href="#" class="dropdown-item">Another action</a> <div class="dropdown-divider"></div> <a href="#" class="dropdown-item">Separated link</a> </div> </div> </div> </div> </body> </html>