Popovers in bootstrap with examples
Bootstrap popover is an attribute in bootstrap that can be used to make any website look more dynamic. Popovers are generally used to display additional information about any element and are displayed on click of mouse pointer over that element. In popover if you click on any element that you include in your script, it will give a particular message as a popover and you can see your message as you defined in the script.
It is easy to implement popovers on a website using Bootstrap as you just need to define a few attributes for the element as described below:
Syntax:
data-toggle="popover" title="Popover Header" data-content="Some content inside the box"
The data-toggle attribute defines the Popover, title attribute defines the Tile for the Popover and data-content attribute is used to store the content to be displayed in the respective Popover.
Include the below javascript in your code to make it work.
<script> $(document).ready(function(){ $('[data-toggle="popover"]').popover(); }); </script> |
Example:
<!DOCTYPE html> <html> <head> <title>Bootstrap Example</title> <!-- Link Bootstrap CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> </head> <body> <div class="container"> <h3>Popover Example</h3> <a href="#" data-toggle="popover" title="Popover Header" data-content="Some content inside the popover">GeeksforGeeks</a> </div> <script> $(document).ready(function(){ $('[data-toggle="popover"]').popover(); }); </script> </body> </html> |
Output:

Different types of Popover orientation in Bootstrap
- Top Alignment: In this type of popover alignment, the popover content is displayed at the top of the element on which we have applied this attribute. To align the popover to the top, assign an attribute data-placement = “top”.
<!DOCTYPE html><html><head><title>Bootstrap Example</title><!-- Bootstrap CSS and JS --><linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"></head><body><divclass="container"><h3>Popover Example</h3><ulclass="list-inline"><li><ahref="#"title="Header"data-toggle="popover"data-placement="top"data-content="Content">GeeksforGeeks</a></li></ul></div><script>$(document).ready(function(){$('[data-toggle="popover"]').popover();});</script></body></html>chevron_rightfilter_noneOutput:
- Left Alignment: In this type of popover alignment, the popover content is displayed at the left of the element on which we have applied this attribute. To align the popover to the top, assign an attribute data-placement = “left”.
<!DOCTYPE html><html><head><title>Bootstrap Example</title><!-- Bootstrap CSS and JS --><linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"></head><body><divclass="container"><h3>Popover Example</h3><ulclass="list-inline"><li><ahref="#"title="Header"data-toggle="popover"data-placement="left"data-content="Content">GeeksforGeeks</a></li></ul></div><script>$(document).ready(function(){$('[data-toggle="popover"]').popover();});</script></body></html>chevron_rightfilter_noneOutput:

- Right Alignment: In this type of popover alignment, the popover content is displayed at the top of the element on which we have applied this attribute. To align the popover to the top, assign an attribute data-placement = “right”.
<!DOCTYPE html><html><head><title>Bootstrap Example</title><!-- Bootstrap CSS and JS --><linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"></head><body><divclass="container"><h3>Popover Example</h3><ulclass="list-inline"><li><ahref="#"title="Header"data-toggle="popover"data-placement="right"data-content="Content">GeeksforGeeks</a></li></ul></div><script>$(document).ready(function(){$('[data-toggle="popover"]').popover();});</script></body></html>chevron_rightfilter_noneOutput:

- Bottom Alignment: In this type of popover alignment, the popover content is displayed at the bottom of the element on which we have applied this attribute. To align the popover to the top, assign an attribute data-placement = “bottom”.
<!DOCTYPE html><html><head><title>Bootstrap Example</title><!-- Bootstrap CSS and JS --><linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"></head><body><divclass="container"><h3>Popover Example</h3><ulclass="list-inline"><li><ahref="#"title="Header"data-toggle="popover"data-placement="bottom"data-content="Content">GeeksforGeeks</a></li></ul></div><script>$(document).ready(function(){$('[data-toggle="popover"]').popover();});</script></body></html>chevron_rightfilter_noneOutput:

Recommended Posts:
- Containers in Bootstrap with examples
- Bootstrap Buttons with Examples
- Borders in bootstrap with examples
- Spacing in Bootstrap with Examples
- List group in bootstrap with examples
- Flexbox utilities in bootstrap with examples
- Visibility of elements in bootstrap with Examples
- BootStrap | Positioning an element with Examples
- Bootstrap | Sizing an element with Examples
- Bootstrap | Float utilities with Examples
- Bootstrap | figure class with Examples
- Display Property in Bootstrap with Examples
- Responsive images in Bootstrap with Examples
- Input Groups in Bootstrap with Examples
- Vertical alignment in Bootstrap with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



