Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Tooltip Not Working with Font Awesome Icon

I am using bootstrap tooltip but I cannot seem to get it to work with a font awesome icon.

I can get this to work:

 <a data-container="body" data-toggle="popover" data-placement="top" title="Other Prep" data-content="Indicates whether or not this product get other prep before shipment" data-original-title="">Info</a>

But this does not work:

 <a data-container="body" data-toggle="popover" data-placement="top" title="Other Prep" data-content="Indicates whether or not this product get other prep before shipment" data-original-title=""><i class="fa fa-info-circle"></i></a>

Here is my javascript:

$(function(){
    $('[data-toggle="popover"]').popover();
    $('body').on('click', function (e) {
        if ($(e.target).data('toggle') !== 'popover'
                && $(e.target).parents('.popover.in').length === 0) {
            $('[data-toggle="popover"]').popover('hide');
        }
    });
});

Does anyone have any help they can shoot me to help me understand why this doesn't work.

Thanks!

like image 435
LargeTuna Avatar asked Aug 27 '14 15:08

LargeTuna


People also ask

How do I enable bootstrap Tooltip?

To create a tooltip, add the data-toggle="tooltip" attribute to an element. Note: Tooltips must be initialized with jQuery: select the specified element and call the tooltip() method.

How do I fix Font Awesome icons not showing?

Make sure you're using the latest and greatest by updating your CDN code reference, updating your Font Awesome package via npm, or downloading a fresh copy of Font Awesome. You can check with version an icon was added to on its detail page (e.g. question-circle was added in Verion 1 but last updated in 5.0. 0).

Are bootstrap tooltips accessible?

Bootstrap's interactive components—such as modal dialogs, dropdown menus and custom tooltips—are designed to work for touch, mouse and keyboard users.

How do I add tooltips to icons?

Answer: Use the Bootstrap . tooltip() method You can apply Bootstrap tooltip on Glyphicons like you do on other elements. First of all add the data attributes data-toggle="tooltip" and data-original-title="Text" to the icon elements and finally initialize the tooltips using the Bootstrap's . tooltip() method.


2 Answers

According to Bootstrap's documentation. You have to initialize the tooltip & popover functionality.

$('[data-toggle="tooltip"]').tooltip();

By the way, you don't need the HTML elements AND the Javascript. Just one or the other. I think (not sure fully) your icon may not be working because it renders with nothing between your a tags. You could try putting a &nbsp; in there.

I was able to get this to work:

<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="left" title="Tooltip on left"></i>

like image 80
Andrew Crawford Avatar answered Oct 26 '22 08:10

Andrew Crawford


You have to set the icon to an inline-block in css:

i.fa {
   display: inline-block;
}

Also you should set this option to the popover:

$(document).ready(function() {
    $("i.fa").popover({'trigger':'hover'});
});

Fiddle: http://jsfiddle.net/ndzqqhfz/2/

like image 38
GlabbichRulz Avatar answered Oct 26 '22 07:10

GlabbichRulz