Skip to content Skip to sidebar Skip to footer

Closing Bootstrap Popover When User Clicks Outside Popover

I have some content that's dynamically loaded on a webpage that contains popovers. For this reason I have to bind them to the body so they load and appear correctly. I'd like to fi

Solution 1:

This relies on internal implementation so be careful but it should work. JSFiddle Link

if ($(this).data('bs.popover').tip().hasClass('in')) {
    $(this).popover('toggle');
}

Solution 2:

Use this code:

$(document).mouseup(function (e) {
    if ($('.popover').has(e.target).length === 0) {
        $('.popover').toggleClass('in').remove();
        return;
    }
});

Post a Comment for "Closing Bootstrap Popover When User Clicks Outside Popover"