I'm currently learning about development and am trying to create a bootstrap dropdown with 3 different background image options. My goal is to change the background based on the selected option from the dropdown. However, I am struggling to figure out how to retrieve the value of the selected option. Despite extensive searching, including the bootstrap documentation, I haven't been able to find a clear solution.
So far, the dropdown displays correctly...
<div class="dropdown open">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Background
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Image 1</a>
<a class="dropdown-item" href="#">Image 2</a>
<a class="dropdown-item" href="#">Image 3</a>
</div>
</div>
...but I am facing difficulties moving forward...
$('#dropdownMenuButton').on('hidden.bs.dropdown', function () {
// Need to extract the selected option value and change the background
})
I am able to change the background, but retrieving the value of the selected option remains a challenge.
It seems like there must be a simpler solution that I am missing. Can someone please offer some guidance?
Thank you,
LB