Solution: How to close Twitter #Bootstrap popover with a click anywhere on the page using #jQuery


Updated September 2, 2015 ‚óŹ 1,517 views

If you are manually triggering a popover using the Boots strap class, chances are you want to close the popover too when user clicks anywhere else on the page.

Use the example code below to achive this goal. That highlighted part of the code closes the popover when a user clicks anywhere on the body of a page.

jQuery(function($) {
    $(".pop-user-info").popover({placement:"top"});
    jQuery("body").on("click",".pop-user-info",function(){
        $(this).popover();
        $(".pop-user-info").not(this).popover("hide"); //hide other popovers
        return false;
    });
    jQuery("body").on("click",function(){
        $(".pop-user-info").popover("hide"); //hide all popovers when clicked on body
    });
});

 

0 Comments




Our Terms of Use and Privacy Policy have changed.
By continuing to use this site, you are agreeing to the new Privacy Policy and Terms of Use.