Answer the question
In order to leave comments, you need to log in
How to prevent the menu from closing when one of its items is clicked (button dropdowns element in Bootstrap)?
Bootstrap has a button element with a dropdown menu ( getbootstrap.com/components/#btn-dropdowns ). I need that when clicking on an item from the menu, the menu itself does not close, but it remains to be closed when clicking outside the menu, how to implement this correctly?
Answer the question
In order to leave comments, you need to log in
on the same stack there is a good solution:
$(document).on(
'click.bs.dropdown.data-api',
'[data-toggle="collapse"]', // тут прописываем селектор, который добавляем к тем .dropdown-menu, которые не должна закрываться по клику на внутренних элементах
function (e) { e.stopPropagation() }
);
Found this one on StackOverFlow :
<script type="text/javascript">
$(document).ready(function() {
$(document).on('click', '.dropdown-menu', function (e) {
$(this).hasClass('keep_open') && e.stopPropagation(); // This replace if conditional.
});
});
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question