I found other answers were either not generic enough, or too complicated. Here is a simple one that should always work (for bootstrap 3):
$('[data-toggle="popover"]').each(function () {
var button = $(this);
button.popover().on('shown.bs.popover', function() {
button.data('bs.popover').tip().find('[data-dismiss="popover"]').on('click', function () {
button.popover('toggle');
});
});
});
Then just add attribute data-dismiss="popover"
in your close button. Also make sure not to use popover('hide')
elsewhere in your code as it hides the popup but doesn't properly sets its internal state in bootstrap code, which will cause issues next time you use popover('toggle')
.