Put your code inside document ready
$(document).ready(function () {
if ($("[rel=tooltip]").length) {
$("[rel=tooltip]").tooltip();
}
});
In my case I was also missing the tooltip css classes on http://twitter.github.com/bootstrap/assets/css/bootstrap.css so son't forget that.
To sum up: activate your tooltips using jQuery selectors
<script type="text/javascript">
$(function () {
$("[rel='tooltip']").tooltip();
});
</script>
In fact, you don't need to use the attribute selector, you can invoke it on any element even if it doesn't have rel="tooltip"
in its tag.
You don't need all js files separately
Just use the following files if you are going to use all bootstrap functions:
-bootstrap.css
-bootstrap.js
both of them can be found in http://twitter.github.com
and finally
-Latest version of jquery.js
For Glyphicons you need the image
glyphicons-halfings.png and/or glyphicons-halfings-white.png(white coloured images)
which you need to upload inside /img/ folder of your website (or) store it where ever you want but change the folder directory inside the bootstrap.css
For tooltip you need the following script inside your
<head> </head>
tag
<script type='text/javascript'>
$(document).ready(function () {
if ($("[rel=tooltip]").length) {
$("[rel=tooltip]").tooltip();
}
});
</script>
That's it...
You need to do the following. Add the
<script type="text/javascript">
$(function () {
$("[rel='tooltip']").tooltip();
});
</script>
code somewhere on your page (preferably in the <head>
section).
Also add data-toggle: "tooltip"
to anything you want to enable with it.
This is the simplest way.
Just put this before </body>
:
<script type="text/javascript">
$("[data-toggle=\"tooltip\"]").tooltip();
</script>
Check out the examples given in the Bootstrap's documentation about tooltips.
For example:
<a href="#"
data-toggle="tooltip"
data-placement="bottom"
title="Tooltip text here">Link with tooltip</a>
If using Rails+Haml is much easier to include the tooltip, just do:
= link_to '', some_path(), :class => "btn btn-success btn-mini icon-plane", :rel => "tooltip", :title => "Referential Guide"
That is just add the following line at the end of the element.
:rel => "tooltip", :title => "Referential Guide"