I am using Bootstrap Popover and popover content is a HTML. I am using below code to initial popover. This code is based on https://stackoverflow.com/a/13203876/1354727 this answer.
Popover content is in div with id #song-status-popover
.
$(".song-status-link").popover({
html: true,
placement: 'bottom',
content: function () {
return $("#song-status-popover").html();
}
});
I wanted to close the popover when I click outside of popover, so I used below code for that:
$('html').on('mouseup', function (e) {
if (!$(e.target).closest('.popover').length) {
$('.popover').each(function () {
$(this).closest('div.popover').popover('hide');
});
}
});
Till now it is doing fine, but I am facing one problem with using both code together. When I open popover and click outside to close it, if I again click on link to open popover, it does not get open in first click. I have to click twice in order to open it.
I want to know what is I am missing and why I am not able to open popover in one click after close it by clicking outside. Please help!
UPDATE: I believe that when I click outside it hides popover, but bootstrap still believes that it is open and on first click it actually consider it closed and on second click it open the popover.