Bootstrap's tooltip doesn't disappear after button click & mouseleave

前端 未结 22 836
感情败类
感情败类 2020-12-07 16:24

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

相关标签:
22条回答
  • 2020-12-07 16:38

    Working Solution

    $(document).on("click",function()
        {
        setTimeout(function()
        {
    
      $('[data-toggle="tooltip"]').tooltip('hide');
    
    },500);    // Hides tooltip in 500 milliseconds
        });
    
    0 讨论(0)
  • 2020-12-07 16:39

    If someone want's to setup a tooltip which will show for some time after click, here is how I did:

    $('[data-toggle="tooltip"]').tooltip({
    trigger : 'click'})  
    
    $('[data-toggle="tooltip"]').on('shown.bs.tooltip', function () {
    $(this).tooltip('hide')
    })
    
    0 讨论(0)
  • 2020-12-07 16:41

    You can also use below method to hide tooltip on mouseleave, As below:

    jQuery("body").on("mouseleave", ".has-tooltip", function(){
        jQuery(this).blur();
    });
    
    0 讨论(0)
  • 2020-12-07 16:44

    This solution worked for me.

    $('a[data-toggle="tooltip"]').tooltip({
      animated: 'fade',
      placement: 'bottom',
      trigger: 'click'
    });
    
    $('a[data-toggle="tooltip"]').click(function(event){
      event.stopPropagation();
    });
    
    $('body').click(function(){
      $('a[data-toggle="tooltip"]').tooltip('hide');
    });
    

    fiddle

    I tried most of the solutions given in previous answers, but none of them worked for me.

    0 讨论(0)
  • 2020-12-07 16:44

    In my case for this was the fix:

    beforeDestroyingElement() {    
      $('[data-toggle="tooltip"]').tooltip('hide');
    }
    

    I wasn't obeying this rule from Bootstrap docs:

    Tooltips must be hidden before their corresponding elements have been removed from the DOM.

    0 讨论(0)
  • 2020-12-07 16:45

    Hi i have little solution for this issue. When other solutions doesn't work just try this one:

    $('body').tooltip({
            selector: '[data-toggle="tooltip"], [title]:not([data-toggle="popover"])',
            trigger: 'hover',
            container: 'body'
        }).on('click mousedown mouseup', '[data-toggle="tooltip"], [title]:not([data-toggle="popover"])', function () {
            $('[data-toggle="tooltip"], [title]:not([data-toggle="popover"])').tooltip('destroy');
        });
    

    This is solution for drag and drop too. So i hope this help someone :)

    0 讨论(0)
提交回复
热议问题