Close popover by clicking outside

Description

The following code shows how to close popover by clicking outside.

Example


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<link rel="stylesheet" type="text/css"
  href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<script type='text/javascript'
  src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
<script type='text/javascript'>
$(window).load(function(){<!--from ww w . jav a  2  s  .  c o  m-->
$('[data-toggle="popover"]').popover();
$('body').on('click', function (e) {
    $('[data-toggle="popover"]').each(function () {
        if (!$(this).is(e.target) && 
             $(this).has(e.target).length === 0 && 
             $('.popover').has(e.target).length === 0) {
            $(this).popover('hide');
        }
    });
});
});
</script>
</head>
<body style='margin:300px'>
  <div class="bs-example tooltip-demo">
    <div class="bs-example-tooltips">
      <button type="button" 
              class="btn btn-default" 
              data-container="body"
        data-toggle="popover" 
        data-placement="top"
        data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."
        data-original-title="" title="">Popover on top</button>
    </div>
  </div>
</body>
</html>

Click to view the demo





















Home »
  Bootstrap »
    Example »




Accordion
Alert
Auto Complete
Badge
Breadcrum
Button
Carousel
Collapse
Dialog
Dropdown
Form
Icon
Jumbotron
Label
Layout
List
List Group
Media
Navigation Bar
Pager
Page Header
Panel
Paragraph
Pills
Popover
ProgressBar
ScrollSpy
Switch
Tab
Table
Thumnail
Tooltip
Tree
Well