Skip to content

Instantly share code, notes, and snippets.

@naganowl
Created April 4, 2014 21:57
Show Gist options
  • Save naganowl/9983873 to your computer and use it in GitHub Desktop.
Save naganowl/9983873 to your computer and use it in GitHub Desktop.
Keep Bootstrap 3.0 dropdown from closing on item click
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>
$(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