The dropdown component of the bootstrap has events to handle all interactions.
show.bs.dropdown-> This event fires immediately when the show instance method is called.
shown.bs.dropdown-> This event is fired when the dropdown has been made visible to the user (will wait for CSS transitions, to complete)
hide.bs.dropdown-> This event is fired immediately when the hide instance method has been called.
hidden.bs.dropdown-> This event is fired when the dropdown has finished being hidden from the user (will wait for CSS transitions, to complete)
Source: link
You can use this code.:
$('.dropdown.keep-open').on({
"shown.bs.dropdown": function() { this.closable = false; },
"click": function() { this.closable = true; },
"hide.bs.dropdown": function() { return this.closable; }
});
Source: link
Home
However when doing tests I found that if we open a second menu the 1st is open.
If it is not the goal you can put this code.:
$('.dropdown').on({
"show.bs.dropdown": function() {
$('.dropdown.open').removeClass('open');
},
"shown.bs.dropdown": function() {
this.closable = false;
},
"click":function() {
this.closable = true;
},
"hide.bs.dropdown": function() {
return this.closable;
}
});
Example:
link