Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap tooltip doesn't show style of the tooltip, only data

Tags:

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

like image 645
Brian Nezhad Avatar asked Aug 05 '14 19:08

Brian Nezhad


People also ask

How do I change the tooltip style?

The tooltip is automatically generated by web browsers, it actually can not be removed or changed. To change the tooltip style, we need to add a tooltip text to a different attribute, for example data-title , then use CSS code to create and customise the style.

How do I change text tooltip in bootstrap?

Useful if you need to change a tooltip's text after it has been initialized: $(this). tooltip('hide') . attr('data-original-title', 'new text') .

How do I make tooltip always show?

Single element To make an element display its tooltip permanently, we use its showTooltipOn property. To make tooltip always be shown, set it to "always" .

Are Bootstrap tooltips accessible?

As you may know, the Twitter bootstrap tooltips are not accessible (I.E. they are not being read by screen readers).


2 Answers

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.

like image 125
1_bug Avatar answered Sep 18 '22 17:09

1_bug


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> 
like image 32
jme11 Avatar answered Sep 17 '22 17:09

jme11