I\'m trying to open a Bootstrap dropdown when I click a item of another dropdown.
The idea is to select a city from the first drop down - then the script will auto o
The best way is to check if the dropdown is not already open, and then to use .dropdown('toggle').
Couple things to be aware of:
$('.dropdown').addClass('open') is not a good replacement for
$('.dropdown-toggle').dropdown('toggle') as suggested in other
answers, because it will cause the dropdown to stay permanently open
instead of closing when you click off of the component.HTML:
JS:
$('.trigger_button').click(function(e){
// Kill click event:
e.stopPropagation();
// Toggle dropdown if not already visible:
if ($('.dropdown').find('.dropdown-menu').is(":hidden")){
$('.dropdown-toggle').dropdown('toggle');
}
});
Fiddle example