After updating from Bootstrap version 4.5.x to 5.0.1, I made changes to how tooltips were initialized. Previously, it was done using
$('[data-toggle="tooltip"]').tooltip({trigger: 'hover'});
, but now it is done differently as shown below:
let tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl, {
container: 'body'
});
})
However, I encountered an issue where the tooltip remains visible even after clicking on the element. In version 4.5.x, this was resolved with
$('[data-toggle="tooltip"]').tooltip("hide");
, but this method no longer works in version 5.
I attempted the following solutions:
let tooltipElement = document.getElementById('myElementwithTooltip');
let tooltip = bootstrap.Tooltip.getInstance(tooltipElement);
tooltip.hide();
// or
tooltip.dispose();
Unfortunately, these methods did not fully resolve the issue. On my website, I have numerous tooltips that serve different purposes such as opening dialogs or providing descriptions for column headers in a datatable plugin with sorting functionality.
The tooltips on the Bootstrap website exhibit the same behavior. Any suggestions or ideas would be greatly appreciated.