Add small overlays of content, like those on the iPad, to any element for housing secondary information.
Popovers whose both title and content are zero-length are never displayed.
Popovers require the tooltip plugin to be included in your version of Bootstrap.
For performance reasons, the Tooltip and Popover data-apis are opt-in, meaning you must initialize them yourself.
One way to initialize all popovers on a page would be to select them by their data-toggle
attribute:
When using popovers on elements within a .btn-group
or an .input-group
, or on table-related elements (<td>
, <th>
, <tr>
, <thead>
, <tbody>
, <tfoot>
), you'll have to specify the option container: 'body'
(documented below) to avoid unwanted side effects (such as the element growing wider and/or losing its rounded corners when the popover is triggered).
To add a popover to a disabled
or .disabled
element, put the element inside of a <div>
and apply the popover to that <div>
instead.
Sometimes you want to add a popover to a hyperlink that wraps multiple lines. The default behavior of the popover plugin is to center it horizontally and vertically. Add white-space: nowrap;
to your anchors to avoid this.
Four options are available: top, right, bottom, and left aligned.
Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.
Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.
Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.
Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.
Use the focus
trigger to dismiss popovers on the next click that the user makes.
For proper cross-browser and cross-platform behavior, you must use the <a>
tag, not the <button>
tag, and you also must include the role="button"
and tabindex
attributes.
Enable popovers via JavaScript:
{% highlight js %}$('#example').popover(options){% endhighlight %}Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-
, as in data-animation=""
.
Note that for security reasons the sanitize
, sanitizeFn
and whiteList
options cannot be supplied using data attributes.
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 |
sanitize | boolean | true | Enable or disable the sanitization. If activated 'template' , 'content' and 'title' options will be sanitized. |
whiteList | object | Default value | Object which contains allowed attributes and tags |
sanitizeFn | null | function | null | Here you can supply your own sanitize function. This can be useful if you prefer to use a dedicated library to perform sanitization. |
Options for individual popovers can alternatively be specified through the use of data attributes, as explained above.
$().popover(options)
Initializes popovers for an element collection.
.popover('show')
Reveals an element's popover. Returns to the caller before the popover has actually been shown (i.e. before the shown.bs.popover
event occurs). This is considered a "manual" triggering of the popover. Popovers whose both title and content are zero-length are never displayed.
.popover('hide')
Hides an element's popover. Returns to the caller before the popover has actually been hidden (i.e. before the hidden.bs.popover
event occurs). This is considered a "manual" triggering of the popover.
.popover('toggle')
Toggles an element's popover. Returns to the caller before the popover has actually been shown or hidden (i.e. before the shown.bs.popover
or hidden.bs.popover
event occurs). This is considered a "manual" triggering of the popover.
.popover('destroy')
Hides and destroys an element's popover. Popovers that use delegation (which are created using the selector
option) cannot be individually destroyed on descendant trigger elements.
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. |