Hi I'm trying to execute a function if the dropdown-menu of bootstrap is closed. Surely I can just add the function call if the menu dropdown-toggle is click. But my concern is what if the user didn't click the dropdown-toggle but instead clicked outside or on other element. The dropdown-menu closes if I click on other element.
Is there a way or is there any callback on bootstrap if the dropdown-menu is closed?
I tried this but its not working
$('.dropdown-menu').on('shown.bs.collapse', function(e) {
alert("Close");
});
You can find dropdown events over here https://getbootstrap.com/docs/3.3/javascript/#dropdowns-events
For quick help
$('.dropdown-menu').on('hide.bs.dropdown', function () {
// your code goes here when dropdown closed
})
Try with this parameter:
$('.dropdown-menu').on('hidden.bs.dropdown', function(e) {
alert("Close");
})
Struggle with this today and resolve it selecting the button id and not the menu class. I was using Bootstrap 5
$('#myDropdownBtnId').on('hidden.bs.dropdown', function(e) {
alert("Dropdown closed!!!");
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.