<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Popover</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div style="padding:50px;">
<a href="#" class="btn btn-primary" data-toggle="popover"
title="Popover Header" data-content="Popover Sample Content">Toggle popover</a>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Directions Popovers</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div style="padding:50px 10px;">
<ul class="list-inline">
<li><a href="#" class="btn btn-primary" title="Sample Header"
data-toggle="popover" data-placement="top" data-content="This is sample content...">
Top Popover</a></li>
<li><a href="#" class="btn btn-success" title="Sample Header"
data-toggle="popover" data-placement="bottom" data-content="This is sample content...">
Bottom Popover</a></li>
<li><a href="#" class="btn btn-warning" title="Sample Header"
data-toggle="popover" data-placement="left" data-content="This is sample content...">
Left Popover</a></li>
<li><a href="#" class="btn btn-info" title="Sample Header"
data-toggle="popover" data-placement="right" data-content="This is sample content...">
Right Popover</a></li>
</ul>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Popovers via JavaScript</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<script type="text/javascript">
$(document).ready(function(){
$(".popover-top").popover({
placement : 'top'
});
$(".popover-right").popover({
placement : 'right'
});
$(".popover-bottom").popover({
placement : 'bottom'
});
$(".popover-left").popover({
placement : 'left'
});
});
</script>
<style type="text/css">
.popover_margin{ margin: 100px 5px;}
.popover_mar_bottom{ margin-bottom: 20px;}
</style>
<div class="popover_margin">
<div class="popover_mar_bottom">
<button type="button" class="btn btn-primary popover-top" data-toggle="popover"
title="Sample title" data-content="This is sample content on Top popover.">Popover on top</button>
<button type="button" class="btn btn-success popover-right" data-toggle="popover"
title="Sample title" data-content="This is sample content on Right popover.">Popover on right</button>
<button type="button" class="btn btn-warning popover-bottom" data-toggle="popover"
title="Sample title" data-content="This is sample content on Bottom popover.">Popover on bottom</button>
<button type="button" class="btn btn-info popover-left" data-toggle="popover"
title="Sample title" data-content="This is sample content on Left popover.">Popover left</button>
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Hiding the Popovers on Next Click</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<style type="text/css">
.popover_margin{ margin: 100px 5px 50px;}
.popover_mar_bottom{ margin-bottom: 20px;}
.hover_margin{ margin:20px 5px;}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="popover"]').popover({
placement : 'top'
});
});
</script>
<div class="popover_margin">
<div class="popover_mar_bottom">
<a href="#" class="btn btn-primary" data-toggle="popover"
tabindex="0" data-trigger="focus" title="Sample Title"
data-content="Default popover">Popover</a>
<a href="#" class="btn btn-success" data-toggle="popover"
tabindex="1" data-trigger="focus" title="Sample Title"
data-content="Another popover">Another popover</a>
<a href="#" class="btn btn-warning" data-toggle="popover"
tabindex="2" data-trigger="focus" title="Sample Title"
data-content="A larger popover to demonstrate the max-width of the Bootstrap popover.">
Large popover</a>
<a href="#" class="btn btn-info" data-toggle="popover"
tabindex="3" data-trigger="focus" title="Sample Title"
data-content="The last tip!">Last popover</a>
</div>
</div>
<h4>Hover Popover</h4>
<div class="hover_margin">
<a href="#" class="btn btn-primary" data-toggle="popover"
data-trigger="hover" title="Sample Title"
data-content="This is Sample Content.">Hover over me</a>
</div>
</div>
</body>
</html>
data-
, as in data-animation=""
.Name | Type | Default | Description |
---|---|---|---|
animation | boolean | true | Apply a CSS fade transition to the popover |
container | string | false | false | Appends the popover to a specific element. Example: |
content | string | function | '' | Default content value if If a function is given, it will be called with its |
delay | number | object | 0 | Delay showing and hiding the popover (ms) - does not apply to manual trigger type If a number is supplied, delay is applied to both hide/show Object structure is: |
html | boolean | false | Insert HTML into the popover. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks. |
placement | string | function | 'right' | How to position the popover - top | bottom | left | right | auto. When a function is used to determine the placement, it is called with the popover DOM node as its first argument and the triggering element DOM node as its second. The |
selector | string | false | If a selector is provided, popover objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have popovers added. See this and an informative example. |
template | string | '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>' | Base HTML to use when creating the popover. The popover's The popover's
The outermost wrapper element should have the |
title | string | function | '' | Default title value if If a function is given, it will be called with its |
trigger | string | 'click' | How popover is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space. manual cannot be combined with any other trigger. |
viewport | string | object | function | { selector: 'body', padding: 0 } | Keeps the popover within the bounds of this element. Example: If a function is given, it is called with the triggering element DOM node as its only argument. The |
Method | Description | Example |
---|---|---|
.popover(options) |
Attaches a popover handler to an element collection. |
$().popover(options)
|
.popover('toggle') |
Toggles an element's popover. |
$('#element').popover('toggle')
|
.popover('show') |
Reveals an element's popover. |
$('#element').popover('show')
|
.popover('hide') |
Hides an element's popover. |
$('#element').popover('hide')
|
.popover('destroy') |
Hides and destroys an element's popover. |
$('#element').popover('destroy')
|
Event Type | Description |
---|---|
show.bs.popover | This event fires immediately when the show instance method is called. |
shown.bs.popover | This event is fired when the popover has been made visible to the user (will wait for CSS transitions to complete). |
hide.bs.popover | This event is fired immediately when the hide instance method has been called. |
hidden.bs.popover | This event is fired when the popover has finished being hidden from the user (will wait for CSS transitions to complete). |
inserted.bs.popover | This event is fired after the show.bs.popover event when the popover template has been added to the DOM. |