I've been playing with the Twitter Bootstrap test page in Dreamweaver and I absolutely can not get any sort of popover, tooltip, or other Bootstrap jQuery goodie to work. I've copied code from the demo page, poured over the source code, have direct links to all the correct JavaScript files, and still nothing. The CSS works fine though, just none of the animation.
The demo page mentions this code for something:
$('#example').popover(options)
But I have no idea what to do with something like that because I didn't see anything like that in any working site.
If anyone could give me any suggestions for the (probably) tiny link I'm missing, I'd greatly appreciate it.
EDIT
I found the following code snippet after posting this:
$(document).ready(function() {
$("a[rel=popover]")
.popover({
offset: 10
})
.click(function(e) {
e.preventDefault()
})
});
And it got the popovers triggering! I never saw anything like that in the source code of any of the working sites I saw though. Really wish the Bootstrap documentation could have made that tiny detail a bit clearer for new jQuery users like me.
To create a popover, add the data-toggle="popover" attribute to an element. Note: Popovers must be initialized with jQuery: select the specified element and call the popover() method.
Tooltips can be enabled via JavaScript — just call the tooltip() Bootstrap method with the id , class or any CSS selector of the target element in your JavaScript code. You can either initialize tooltips individually or all in one go.
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.
To show or hide the Popover programmatically, call the show() or hide() method. The same thing can be done using the toggle(showing) method. Pass true or false to this method to show or hide the Popover, respectively. This approach is more typical of jQuery Controls.
For people coming here from Google:
You can get tooltip and popover to work automatically like the other Bootstrap plugins with the following code:
<script type="text/javascript">
$(function () {
$('body').popover({
selector: '[data-toggle="popover"]'
});
$('body').tooltip({
selector: 'a[rel="tooltip"], [data-toggle="tooltip"]'
});
});
</script>
You can then use data attributes like normal:
<a rel="tooltip" title="My tooltip">Link</a>
<a data-toggle="popover" data-content="test">Link</a>
<button data-toggle="tooltip" data-title="My tooltip">Button</button>
This is what the Bootstrap docs mean when it says that the data-api for these plugins are "opt in".
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