How do I bind Twitter Bootstrap tooltips to dynamically created elements?
If you have multiple tooltip configurations that you want to initialise, this works well for me.
$("body").tooltip({
selector: '[data-toggle="tooltip"]'
});
You can then set the property on individual elements using data
attributes.
I've posted longer answer here: https://stackoverflow.com/a/20877657/207661
TL;DR: You need only one line of code that runs in document ready event:
$(document.body).tooltip({ selector: "[title]" });
Other more complicated code suggested in other answers don't seem necessary (I've tested this with Bootstrap 3.0).
For me, only catching the mouseenter event was a bit buggy, and the tooltip was not showing/hiding properly. I had to write this, and it is now working perfectly:
$(document).on('mouseenter','[rel=tooltip]', function(){
$(this).tooltip('show');
});
$(document).on('mouseleave','[rel=tooltip]', function(){
$(this).tooltip('hide');
});
Try this one:
$('body').tooltip({
selector: '[rel=tooltip]'
});