I have a problem with bootstrap\'s tooltip : When I click on a button, tooltip stays even if is the cursor is outside of the button. I have looked into the manual - Bootstra
My problem is in DataTable. Below code works for me.
columnDefs: [
{
targets: 0, data: "id",
render: function (data, type, full, meta) {
return '<a href="javascript:;" class="btn btn-xs btn-default" data-toggle="tooltip" title="Pending" data-container="body"><i class="fa fa-check"></i></a>';
}
}
],
drawCallback: function() {
$('[data-toggle="tooltip"]').tooltip();
$('[data-toggle="tooltip"]').on('click', function () {
$(this).tooltip('hide');
});
}
Using delegation to make it ajax friendly,
// if you're not using turbolinks, then you can remove this parent wrapper
$(document).on('turbolinks:load'), function() {
// enable tooltip with delegation to allow ajax pages to keep tooltip enabled
$('body').tooltip({
select: "[data-toggle='tooltip']"
});
// remove old tooltip from sticking on the page when calling ajax with turbolinks
$('body').on('click', "[data-toggle='tooltip']", function() {
$(this).tooltip('dispose');
});
});
I know over a year old, but I couldn't get this to work with any examples here. I've had to use the following:
$('[rel="tooltip"]').on('click', function () {
$(this).tooltip('hide')
})
This also shows the tooltip again upon hover.
The way I fixed this issue was by removing the tooltip in the click event function using the following code:
$("#myButton").on("click", function() {
$("div[role=tooltip]").remove();
});
Try using rel="tooltip"
instead of data-toggle="tooltip"
which worked in my case. I was using data-toggle="tooltip"
and also set the trigger condition as hover which didn't work in my case. When I changed my data selector, it worked.
HTML Code:
<button id="submit-btn" type="submit" class="btn btn-success" rel="tooltip" title="Click to submit this form">Submit</button>
JS Code //Tooltip $('.btn').tooltip({ trigger: 'hover' });
This will definitely remove the stuck tooltip.
This is because trigger
is not set. The default value for trigger is 'hover focus'
, thus the tooltip stay visible after a button is clicked, until another button is clicked, because the button is focused
.
So all you have to do is to define trigger
as 'hover'
only. Below the same example you have linked to without persisting tooltips after a button is clicked :
$('[data-toggle="tooltip"]').tooltip({
trigger : 'hover'
})
the doc example in a fiddle -> http://jsfiddle.net/vdzvvg6o/