I am trying to put checkboxes in a bootstrap dropdown. I do not want the dropdown to close on click but I still want it close if they click else where on the website. I still want to fire off other javascript actions on click with in the dropdown. I have an example of the exact inverse of what I want. This example closes the drop down on click but keeps it open when clicked from the outside the dropdown area.
$(function () {
$('.dropdown.keep-open').on({
"shown.bs.dropdown": function() {
$(this).data('closable', false);
},
"click": function() {
$(this).data('closable', true);
},
"hide.bs.dropdown": function() {
return $(this).data('closable');
}
});
});
http://jsfiddle.net/KyleMit/ZS4L7/
I finally got it. the code is below:
$(function() {
$('.dropdown.keep-open').on({
"shown.bs.dropdown": function() {
$(this).data('closable', false);
},
"click": function(event) {
$(this).data('closable', false);
},
"hide.bs.dropdown": function(event) {
temp = $(this).data('closable');
$(this).data('closable', true);
return temp;
}
});
});
Edit: Added missing semicolon on line 11.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With