Bootstrap Popover
\\n\\nBootstrap Popover is created using a custom jQuery plugin. It can be used to display some information about any element.
\\n\\nIn this tutorial, you will see how to use Bootstrap Popover and how to customize it using some available options.
\\n\\nYou must reference jQuery, Bootstrap CSS, and two JavaScript filesβone for the Bootstrap Tooltip plugin and one for the Bootstrap Popover plugin.
\\n\\nThe JS file for the Tooltip plugin is located in the js folder of your Bootstrap directory and is named bootstrap-tooltip.js. The JS file for the Popover plugin is located in the js folder of your main Bootstrap directory and is named bootstrap-popover.js. jQuery is located under docs > assets > js in your main Bootstrap folder and is named jquery.js. Alternatively, you can directly access https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js to download jQuery.
Make sure you download bootstrap-tooltip.js before downloading bootstrap-popover.js. Popover depends on the Tooltip plugin, so the Tooltip plugin must be loaded first.
Example
\\n\\nCreate a Popover with Bootstrap
\\n\\nThe table below explains the code above. It will help you understand how to use Bootstrap Popover.
\\n\\n| Code | \\nExplanation | \\n
|---|---|
id="example" | \\nThe ID assigned to the relevant anchor element. The value of the ID points to the JavaScript that implements the popover later. | \\n
class="btn btn-danger" | \\nCreates a button. btn btn-danger is the class used in this example. You can use any other class from Bootstrap CSS or define your own class. | \\n
data-content="It's so simple to create a tooltip for my website!" | \\nThe value of data-content is displayed in the body of the popover. | \\n
data-original-title="Bootstrap Popover" | \\nThe value of data-original-title is displayed as the title of the popover. | \\n
hover for popover | \\nThe anchor text. | \\n
<script src="https://ajax.googleapis.com/ajax/libs/ jquery/1.7.1/jquery.min.js"></script> | \\nReferences jQuery. | \\n
<script src="../bootstrap/twitter-bootstrap-v2/ js/bootstrap-tooltip.js"></script> | \\nReferences the Bootstrap Tooltip plugin JS file. | \\n
<script src="../bootstrap/twitter-bootstrap-v2/js/ bootstrap-popover.js"></script> | \\nReferences the Bootstrap Popover plugin JS file. | \\n
$(function () | \\nPrepares the document. A jQuery command. | \\n
$("#example").popover(); | \\nAccesses the element with ID example and applies popover() to it. | \\n
Here, we created a popover without any customization outside the boxβthat is, we didnβt pass any options to popover().
Therefore, we can summarize the usage of Bootstrap Popover as:
\\n\\n$(function () { $("identifier").popover(options); });
\\nWhere identifier is a jQuery selector identifying the relevant container element. Next, letβs look at what options are available.
Below are some options you might use with popover() to customize the appearance and behavior of the Popover.
animation
\\n\\nThe animation option accepts a boolean value and defaults to true. It adds a CSS fade transition effect to the tooltip.
placement
\\n\\nThe placement option accepts a string or function and defaults to 'right'. Other possible values include 'top', 'bottom', and 'left'. This option determines the position of the Popover relative to the anchor text. Below is an example using the placement option.
Example
\\n\\nCreating a Popover using the Bootstrap placement option
\\n\\nselector
\\n\\nThe selector option accepts a string and defaults to false. Using this option delegates the Tooltip object to the specified target.
trigger
\\n\\nThe trigger option accepts a string and defaults to 'hover'. Other possible values include 'focus' and 'manual'. This option determines how the tooltip is triggered. The following example demonstrates how to trigger a Popover using the focus option.
Example
\\n\\nCreating a Popover using the Bootstrap trigger option
\\n\\ntitle
\\n\\nThe title option accepts a string or function and defaults to '' (empty string), meaning the title attribute value is not displayed by default.
content
\\n\\nThe content option accepts a string or function and defaults to '' (empty string), meaning the data-content attribute value is not displayed by default. Below is an example using both the title and content options. This example also demonstrates how to use multiple options together.
YouTip