Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap tooltip doesn't go away with a back button click and AJAX calls

I am having an issue where the bootstrap 4 tooltips doesn't go away with the browser's back button click:

enter image description here

I am using rails, and I do have this code:

document.addEventListener('turbolinks:load', () => {
    $('[data-toggle="tooltip"]').tooltip({
        trigger: 'hover'
    })

    $('[data-toggle="popover"]').popover()
})

The trigger: hover is working, and I got the suggestion from Bootstrap's tooltip doesn't disappear after button click & mouseleave

But they survive a back button click.

Edit, similar thing is happening with AJAX calls: enter image description here

Solved:

This code hides the tooltip whenever the element is clicked, this solves the issue.

    $('[data-toggle="tooltip"]').tooltip({
        trigger: 'hover'
    }).on('click', function() {
        $(this).tooltip('hide')
    })
like image 997
S.Goswami Avatar asked Oct 27 '25 06:10

S.Goswami


1 Answers

On Bootstrap 5, you need the following selector:

$('[data-bs-toggle="tooltip"]').tooltip({
  trigger: 'hover'
}).on('click', function() {
  $(this).tooltip('hide')
})
like image 67
Ariadni Makari Avatar answered Oct 28 '25 21:10

Ariadni Makari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!