"Popover closes on unfocus"
Bootstrap 3.2.0 Snippet by diglididudeng

<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <p><a id="YOUR_BUTTON_FOR_POPOVER" class="btn btn-primary" role="button" data-toggle="popover" href="#">Click me</a>, then click somewhere else afterwards !</p> </div> </div>
body { display: block; position: relative; width: 100%; height: 800px; background-color: #ddd; }
$(document).ready(function() { // Example popover. // Replace it with your own implementation. $('#YOUR_BUTTON_FOR_POPOVER').popover({ animation: true, placement: 'bottom', trigger: 'focus', title: 'See?', content: 'Now try clicking outside !' }).on("click", function() { $(this).popover("show"); }) // Where the magic happens !!! // // NOTE: it does not need you changing anything, // unless you only want specific popovers to disappear // after unfocusing. $('body').on('click', function (e) { //only buttons if ($(e.target).data('toggle') !== 'popover' && $(e.target).parents('[data-toggle="popover"]').length === 0 && $(e.target).parents('.popover.in').length === 0) { $('[data-toggle="popover"]').popover('hide'); } }); });

Related: See More


Questions / Comments: