I want to use the javascript provided in Tritter´s Bootstrap. I´ve checked that all the .js files are pointed out ok.
I want to test if it works ok, so after reading the docs, I understand that I have to "call" the appropiate javascript function?
Using bootstrap-tooltip.js Trigger the tooltip via javascript: $('#example').tooltip(options)
How may I call that function? It seems that it´s not enough to put the proper html, I have to call the function aswell?
Thanks for your help!!
Give a HTML element the ID of example
and appropriate attributes like this:
<p><a href="#" rel="tooltip" title="first tooltip" id="example">hover over me</a>,/p>
In your <head>
create a JavaScript <script>
element, make sure jQuery is loaded and then, within the jQuery, add the tooltip to the element with the ID of example
:
<script type="text/javascript">
window.onload = function()
{
if(!window.jQuery)
{
alert('jQuery not loaded');
}
else
{
$(document).ready(function(){
$('#example').tooltip({'placement':'top', 'trigger' : 'hover'});
});
}
}
</script>
This will setup a tooltip when you hover over the #example
element. Change top
to left
, right
or bottom
to change where the tooltip is placed in relation to the element itself.
In case you might want to in the future, this is how you'd set up a popover also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With