screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <title>Bootstrap Dropdown Example</title> </head> <body> <div class="container mt-5"> <h3>Change Bootstrap Dropdown Button Text with jQuery on Selection</h3> <div class="dropdown"> <button class="btn btn-warning dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Select an option </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <li><a class="dropdown-item" href="#" data-value="Bard">Bard</a></li> <li><a class="dropdown-item" href="#" data-value="Chatgpt">Chatgpt</a></li> <li><a class="dropdown-item" href="#" data-value="Grok">Grok</a></li> <li><a class="dropdown-item" href="#" data-value="Python">Python</a></li> <li><a class="dropdown-item" href="#" data-value="JavaScript">JavaScript</a></li> <li><a class="dropdown-item" href="#" data-value="HTML">HTML</a></li> <!-- Add more items as needed --> </ul> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script> $(document).ready(function () { $('.dropdown-item').on('click', function () { var selectedText = $(this).data('value'); $('#dropdownMenuButton').text(selectedText); }); }); </script> </body> </html>