- Forked from http://jsfiddle.net/KyleMit/ZS4L7/
- Example here http://jsfiddle.net/YqF68/5/
- Useful for when you have a list of checkboxes which you want to let a user interact with (Such as filters).
- The two handlers should be cleaned up where appropriate (On view disposal for Backbone).
Created
April 4, 2014 21:57
-
-
Save naganowl/9983873 to your computer and use it in GitHub Desktop.
Keep Bootstrap 3.0 dropdown from closing on item click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Click the dropdown to Open <br/> | |
It will stay open unless clicked again to close | |
<div class="dropdown keep-open"> | |
<!-- Dropdown Button --> | |
<button id="dLabel" role="button" href="#" | |
data-toggle="dropdown" data-target="#" | |
class="btn btn-primary"> | |
Dropdown <span class="caret"></span> | |
</button> | |
<!-- Dropdown Menu --> | |
<ul class="dropdown-menu" role="menu" | |
aria-labelledby="dLabel"> | |
<li><a href="#">Action</a></li> | |
<li><a href="#">Another action</a></li> | |
<li><a href="#">Something else here</a></li> | |
<li class="divider"></li> | |
<li><a href="#">Separated link</a></li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
var dropdown = $('.dropdown.keep-open'); | |
$(document).on('click.bs.dropdown.data-api', function (e) { | |
// See if clicked element is outside the dropdown. | |
if (dropdown.find(e.target).length === 0) { | |
dropdown.removeClass('open'); | |
} | |
}); | |
dropdown.on("hide.bs.dropdown", function(e) { | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment