Home:ALL Converter>Check the status of Bootstraps of dropdown menu

Check the status of Bootstraps of dropdown menu

Ask Time:2019-10-24T22:19:27         Author:chen

Json Formatter

I want to use jQuery to open and close the dropdown. I checked this question, but it is about open only. How to open Bootstrap dropdown programmatically I found these two command to open it and close it.

$('.dropdown-menu').show();
$('.dropdown-menu').close();

However, how can I know the current status of the dropdown? I want click to close if it is open, and click to open if it is close.

Author:chen,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58543371/check-the-status-of-bootstraps-of-dropdown-menu
Abderrahim Soubai-Elidrisi :

You can listen to the event :\n\n// var to be visible in the global scope\n\nvar status = false; // default hidden \n\n$('#myDropdown').on('hidden.bs.dropdown', () => status = false)\n\n$('#myDropdown').on('shown.bs.dropdown', () => status = true)\n\n\nLater you can check for the status value;",
2019-10-24T14:24:45
yy