$(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');
}
});
});