Was it helpful?

Question

Popovers in Bootstrap with examples

BootstrapWeb DevelopmentFront End Technology

A popover is a simple tooltip plugin. A popover is a box of content that pops up when the user clicks on a specific element. This plugin relies on popover.js.

Creating Popovers in HTML

The attribute data-toggle = "popover" is used to create a popover in HTML. Adding this attribute to an element converts it to a popover.

Syntax

<a href=”” data-toggle = "popover" title="popover title" data-content="popover content" >popover display</a>

Example

 Live Demo

<!DOCTYPE html>
<html lang="en" >
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h3>Popover In BootStap</h3><br><br>
<a href="#" data-toggle="popover" title="Welcome Text" data-content="Learning Bootstrap from TutorialsPoint!">Learn BootStrap</a>
</div>
<script>
$(document).ready(function(){
   $('[data-toggle="popover"]').popover();
});
</script>
</body>
</html>

Output

Positioning Popovers

You can position popovers using the data-placement attribute. By default, a popover appears on the right of the element. Let’s see the positioning of popovers in different directions −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title<Bootstrap Example</title<
<meta charset="utf-8"<
<meta name="viewport" content="width=device-width, initial-scale=1"<
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"<
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"<</script<
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"<</script<
</head>
<body>
<div class="container">
<h3>Popover Example</h3>
<a href="#" data-toggle="popover" title="Popover Header" data-placement="right" data-content="Some content inside the popover">Toggle popover right</a><br><br><br><hr>
<a href="#" data-toggle="popover" title="Popover Header" data-placement="top" data-content="Some content inside the popover">Toggle popover Top</a><br><br><br><hr>
<a href="#" data-toggle="popover" title="Popover Header" data-placement="left" data-content="Some content inside the popover">Toggle popover left</a><br><br><br><hr>
<a href="#" data-toggle="popover" title="Popover Header" data-placement="bottom" data-content="Some content inside the popover">Toggle popover bottom</a><br><br><br><hr>
</div>
<script>
$(document).ready(function(){
   $('[data-toggle="popover"]').popover();
});
</script>
</body>
</html>

Output

raja
Published on 17-Apr-2020 12:15:22
Advertisements
Was it helpful?
Not affiliated with Tutorialspoint
scroll top