3

is it possible to close a bootstrap popover when you click outside the popover but when you click inside the popover it stays open. I know this has been discussed before in here but this one also closes when you click inside the popover.

Here is their demo: http://jsfiddle.net/Sherbrow/e6Gt8/

    var $poped = $('.poped');
$poped.popover();

// Trigger for the popover
$poped.each(function() {
    var $this = $(this);
    $this.on('hover',function() {
            var popover = $this.data('popover');
            var shown = popover && popover.tip().is(':visible');
            if(shown) return;        // Avoids flashing
            $this.popover('show');
    });
});

// Trigger for the hiding
 $('html').on('click.popover.data-api',function() {
    $poped.popover('hide');
});

Community
  • 1
  • 1
Chanckjh
  • 2,587
  • 2
  • 22
  • 28

1 Answers1

4

Have a look at http://jsfiddle.net/VcwUm/

// Trigger for the hiding
$('html').on('click.popover.data-api',function(e) {
     if($(e.target).has('.poped').length == 1){
         $poped.popover('hide');
     } else {
         return false;
     }
});

All I'm doing is checking if the target element has a child with a certain class to decide if I should close the popup or not.

boz
  • 4,891
  • 5
  • 41
  • 68