//test.js
const dropdownMenu = document.querySelector('.dropdown-menu');
dropdownMenu.addEventListener('click', (event) => {
alert(`You clicked on ${event.target.textContent}`);
});
// index.html
<div class="dropdown">
<button class="btn btn-primary" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Click to toggle popover
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Volvo</a>
<a class="dropdown-item" href="#">Saab</a>
<a class="dropdown-item" href="#">Mercedes</a>
<a class="dropdown-item" href="#">Audi</a>
</div>
</div>
I am able to get the button to show the menu, but I need help with making alerts pop up when selecting an item from the menu. Can someone assist me with this? Thank you!
Appreciate any assistance provided.