The show.bs.dropdown event fires just before the dropdown menu is shown. The shown.bs.dropdown event fires after it is fully visible.
$('#myDropdown')._____('toggle');
The correct method is dropdown('toggle'). Other options are not valid Bootstrap dropdown methods.
<button id="menuBtn" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Menu</button> <ul class="dropdown-menu" aria-labelledby="menuBtn"> <li><a class="dropdown-item" href="#">Item 1</a></li> <li><a class="dropdown-item" href="#">Item 2</a></li> </ul> <script> const btn = document.getElementById('menuBtn'); btn.addEventListener('shown.bs.dropdown', () => { alert('Dropdown is now visible'); }); </script>
Clicking the button toggles the dropdown open. The event listener triggers an alert after the menu is visible.
The class show is added to the dropdown menu when visible. The selector .dropdown-menu.show matches only visible menus.
Option D is invalid CSS, option D targets the toggle button, and option D is not used by Bootstrap for dropdown visibility.
The aria-expanded attribute on the dropdown toggle button should be set to true when the menu is open and false when closed. This helps screen readers announce the state.
