Bootstrap Tutorial - Control Popover via Javascript Methods








The following code shows how to control Popover via Javascript Methods.

Example

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet"
  href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet"
  href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<script type="text/javascript"
  src="http://code.jquery.com/jquery.min.js"></script>
<script
  src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--   w ww . j a  va  2  s  . c om-->
    $(".show-popover").click(function(){
       $(".popover-examples a").popover('show');
    });
    $(".hide-popover").click(function(){
       $(".popover-examples a").popover('hide');
    });
    $(".toggle-popover").click(function(){
       $(".popover-examples a").popover('toggle');
    });
    $(".destroy-popover").click(function(){
       $(".popover-examples a").popover('destroy');
    });
});
</script>
<style type="text/css">
.bs-example {
  margin: 100px 50px;
}

.popover-examples {
  margin-bottom: 60px;
}
</style>
</head>
<body>
  <div class="bs-example">
    <p class="popover-examples">
      <a href="#" title="Popover title" class="btn btn-lg btn-primary"
        data-toggle="popover"
        data-content="And here's some amazing content. It's very engaging.">Popover
        Example</a>
    </p>
    <div class="popover-controls">
      <p>Click on the following buttons to control the popover
        manually.</p>
      <input type="button" class="btn btn-info show-popover" value="Show">
      <input type="button" class="btn btn-warning hide-popover"
        value="Hide"> <input type="button"
        class="btn btn-success toggle-popover" value="Toogle"> <input
        type="button" class="btn btn-danger destroy-popover" value="Destroy">
    </div>
  </div>
</body>
</html>

Click to view the demo