tolik
tolik

Reputation: 187

Image in Bootstrap Tooltip

I am trying to show a tooltip with an image in some pages of my website. But, somehow, when I try to use the tooltip from bootstrap, only the path to the image is shown and not a tooltip. Can anyone give a hint, what is eventually wrong?

$(function() {
  $('[data-toggle="tooltip"]').tooltip({
    html:true
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
    
<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />
    
<!-- Latest compiled Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>


<label class="checkbox">
  @{
    var imageSrc = Server.MapPath("~/Content/Images/1.jpg");
   }
  <a href="#" data-toogle="tooltip" title="<img src='@imageSrc'/>">
    Style no. 1
  </a>
</label>

Upvotes: 3

Views: 7885

Answers (2)

Ashu Mhatugade
Ashu Mhatugade

Reputation: 80

Try this one:

$('a[data-toggle="tooltip"]').tooltip({
    animated: 'fade',
    placement: 'bottom',
    html: true
});

<a data-toggle="tooltip" title="<img src='http://getbootstrap.com/apple-touch-icon.png'/>">
        <i class="icon-shopping-cart"></i>
    </a>

Also, refer https://www.tutorialrepublic.com/faq/how-to-insert-image-inside-bootstrap-popover.php

Upvotes: 0

fen1x
fen1x

Reputation: 5880

Fix typo (data-toggle instead of data-toogle) and everything will work:

$(function() {
  $('[data-toggle="tooltip"]').tooltip({
    html: true
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />

<!-- Latest compiled Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>


<label class="checkbox">
  <a href="#" data-toggle="tooltip" title="<img class='img-thumbnail' src='https://picsum.photos/200/100'/>">
    Style no. 1
  </a>
</label>

Upvotes: 9

Related Questions