24

Trying to make Bootstrap show the tooltip function, I have followed exactly as Bootstrap DOC about Tooltips and declare my attribute and properties. when I hover over the text the data Some tooltip text! shows as there is alt="" function only, but not in style as Bootstrap mentioned in their document.

Steps I have taken to resolve this issue:

  1. Include tooltip.js from external CDN
  2. activate tooltip throw <Script>$('[data-toggle="tooltip"]').tooltip({'placement': 'top'});</script>
  3. Add Google API of jQuery (I know is not neccessery)
  4. check if the page is loading the Bootstrap CDN and external ones (All Do!)

Header HTML Markup

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/style.css" rel="stylesheet">
<!-- Latest compiled and minified JavaScript -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

HTML Markup

<a href="#" data-toggle="tooltip" title="Some tooltip text!">Hover over me</a>

Here is an image of how it shows.

enter image description here

Francisco
  • 10,918
  • 6
  • 34
  • 45
Brian Nezhad
  • 6,148
  • 9
  • 44
  • 69

11 Answers11

44

Remember also that Bootstrap Tooltip don't like jQuery UI (there are a few names conflict and 'tooltip' is one of them).

The solution is changing the script loading order: jQuery UI first, bootstrap.js after.

1_bug
  • 5,505
  • 4
  • 50
  • 58
17

Here's a working template for you. My guesses as to what was wrong:

  1. jQuery always needs to come before bootstrap.js.
  2. If you don't have a local server running, you need to add the http: to the CDN addresses.
  3. You may have been trying to initialize the tooltip in the head tags. Problem is that the document probably wasn't ready.

The following works fine.

HTML:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <a href="#" data-toggle="tooltip" title="Some tooltip text!">Hover over me</a>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script>
    $( document ).ready(function() {
        $('[data-toggle="tooltip"]').tooltip({'placement': 'top'});
    });
    </script>
  </body>
</html>
jme11
  • 17,134
  • 2
  • 38
  • 48
  • Wow, you solve it man, I needed to initialize it after CDN, but why it didn't worked when the CDN was in header and initialization was after link? @jme11 – Brian Nezhad Aug 05 '14 at 19:45
  • 2
    Because it was looking for an element with a data-toggle="tooltip" attribute and the element wasn't loaded yet. Think of the page as loading top to bottom. Anyway, it's better to put your js at the bottom of the page before your closing body tag. For users, this will give the impression of faster load times because the page content loads without having to wait for the javascript to load. – jme11 Aug 05 '14 at 19:52
  • Interesting, Thanks and Cheers! now trying to Enable popovers, do you know if i have initialize it as well? @jme11 – Brian Nezhad Aug 05 '14 at 19:54
  • Yes, same concept, just add the initialization inside the same document ready before the closing }); bit. – jme11 Aug 05 '14 at 19:57
  • I had jQuery before Bootstrap but I've found out, that Bootstrap needs to be even after JQuery UI. – Daniel Székely Aug 10 '16 at 09:26
12

Your problem is more than likely that you failed to initialize the tooltip correctly. Take a look at this bootply

The documents state:

enter image description here

HTML:

<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="right" title="Tooltip on right">Tooltip on right</button>

Jquery:

$("[data-toggle=tooltip").tooltip();
  1. Remember you only need bootstrap.min.css and bootstrap.js for the tooltip to work correctly.
  2. Remember to load scripts and style sheets using absolute URLs (add / in front of path).
  3. bootstrap depends on jquery, load jquery first.
Jordan.J.D
  • 7,999
  • 11
  • 48
  • 78
  • I did initialize it, `` – Brian Nezhad Aug 05 '14 at 19:41
  • @BrianS the only files you need are bootstrap.css and bootstrap.js for the tooltip to work. please add `/` in front of all paths. Other than that, if you fixed the order of script loading, it is in your custom css that makes the problem. – Jordan.J.D Aug 05 '14 at 19:44
3

The OP described precisely the issue I was seeing in Angular 8 with Bootstrap 4.4.1 using JQuery 3.4.1 and not using ng-bootstrap or ngx-bootstrap. The image in the OP is bang on.

Some of the answers were sort of helpful while missing the key point that if the DIV is wrapped in an *ngIf it is difficult to get tooltip() to see that the DIV should have a listener attached to it for mouseenter / mouseleave events. Doing this as the document loads the first time is useless for a single page application where the content is dynamically added and removed.

The critical answer turned up https://github.com/twbs/bootstrap/issues/4215 and codepen https://codepen.io/Johann-S/pen/djJYPb . For me the fix was ...

app.component.ts ... just once in this one file is enough

import { Component } from '@angular/core'
declare var $: any
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.sass']
})
export class AppComponent {
    constructor(){
        $('body').tooltip({
            selector: '[data-toggle="tooltip"]'
        })
    }
}

and in every place the tooltip should be seen (component.html files for me).

<div data-toggle="tooltip" data-placement="top" title="Tool Tip Text">

Binding to the body allows the tooltip selector to see the addition of any 'new' DOM elements irrespective of the timing.

As to the performance hit ... not sure yet :D, though it is mercifully light on typing.

jwal
  • 630
  • 6
  • 16
1

Try adding this code at the bottom of your HTML i've needed it to trigger the tooltip to work. Add class="ttop" to your tooltips in HTML code.

$(document).ready(function(){
$(".ttop").tooltip({
    placement : 'top'
});
});
DivineChef
  • 1,211
  • 1
  • 10
  • 27
1

In my case using AngularJS, even all css/js scripts were sequenced/invoked properly but still wasn't showing.

The issue was it's under from a tag with "ng-if" attribute. After I placed it outside from that tag It works fine.

Maybe there's a slight delay with AngularJS rendering the elements with "ng-if" while jquery is initialising the tooltip.

babidi
  • 506
  • 5
  • 6
0

You must initialize tooltip like:

$('[data-toggle="tooltip"]').tooltip()
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Four
  • 31
  • 5
0

If you are using popper.js with bootstrap 4, instead of using:

<script src="~/Scripts/popper.min.js"></script>

use the .js in the UMD directory:

<script src="~/Scripts/umd/popper.min.js"></script>
Exel Gamboa
  • 936
  • 1
  • 14
  • 25
0

All your jquery*.js files must come before bootstrap.js.

jquery-{version}.js
jquery-confirm.min.js
jquery-ui-{version}.js
jquery.validate*
etc...
bootstrap.js

Then use:

<script>
$(document).ready(function () {
    $('[data-toggle="tooltip"]').tooltip();
});
</script>
BSchu
  • 1
0

make sure if you add bootstrap.min.js and also add

<script> $(document).ready(function () { $('[data-toggle="tooltip"]').tooltip(); }); </script>
Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
0

This question has been sufficiently answered, but the solutions don't apply; my links were in good order. Turns out that there's a conflict with Font Awesome (FA). For example, this wouldn't work for me:

<span class="fas fa-search" data-toggle="tooltip" title="Search my site"></span>

If I remove the FA classes, and enter text within the span, the tooltips render in the proper style... but isn't a good solution. However, by encapsulating that span within another span does work:

<span data-toggle="tooltip" title="Search my site"><span class="fas fa-search"></span></span>

I hope this helps the odd soul out there. Or two :^)

yapdog
  • 106
  • 4