How to insert image inside Bootstrap popover

Topic: Bootstrap / Less« Prev|Next »

Answer: Use the Popover's content Option

You can pass the content option to the Bootstrap .popover() method to insert the images inside the popovers. You can also set this option using the data-content attribute.

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="UTF-8">
  • <title>Show Images in Bootstrap Popovers</title>
  • <link rel="stylesheet" href="css/bootstrap.min.css">
  • <link rel="stylesheet" href="css/bootstrap-theme.min.css">
  • <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
  • <script src="js/bootstrap.min.js"></script>
  • <script type="text/javascript">
  • $(document).ready(function(){
  •     $('[data-toggle="popover"]').popover({
  •         placement : 'top',
  •         trigger : 'hover',
  •         html : true,
  •         content : '<div class="media"><a href="#" class="pull-left"><img src="../images/avatar-tiny.jpg" class="media-object" alt="Sample Image"></a><div class="media-body"><h4 class="media-heading">Jhon Carter</h4><p>Excellent Bootstrap popover! I really love it.</p></div></div>'
  •     });
  • });
  • </script>
  • <style type="text/css">
  •     .bs-example{
  •         margin: 200px 150px 0;
  •     }
  • </style>
  • </head>
  • <body>
  •     <div class="bs-example">
  •         <button type="button" class="btn btn-primary" data-toggle="popover">Popover without Title</button>
  •         <button type="button" class="btn btn-primary" data-toggle="popover" title="User Info">Popover with Title</button>
  •     </div>
  • </body>
  • </html>

Related FAQ

Here are some more FAQ related to this topic:

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.