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

前端 未结 22 905
感情败类
感情败类 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 17:01

    Also you can use this way for old versions because the accepted answer didn't worked for me and I wrote this code for my self and its work well.

    $(document).on('mousedown', "[aria-describedby]", function() {
        $("[aria-describedby]").tooltip('hide');
    });
    
    0 讨论(0)
  • 2020-12-07 17:03

    I'm using bootstrap tooltip in cycle.js and none of the above worked for me.

    I had to do this:

    return button( selector + '.btn.btn-sm', 
                 {
                   hook: {
                     destroy: tooltipOff,
                     insert:  toggleTooltipOn,
                   },
    ....
    
    function toggleTooltipOn(vnode){
      setupJQuery();  
      jQuery[0].$( vnode.elm )
        .tooltip({container:'body', trigger: 'hover');
    //container:body is to help tooltips not wiggle on hover
    //trigger:hover is to only trigger on hover, not on click
    }
    
    function tooltipOff( vnode ){
      setupJQuery();      
      jQuery[0].$( vnode.elm ).tooltip('hide');
    }
    
    0 讨论(0)
  • 2020-12-07 17:04

    Also you can add:

    onclick="this.blur()"
    
    0 讨论(0)
  • 2020-12-07 17:04

    David's answer above helped to fix my problem. I had both hover and click event on the button. Firefox on MAC did behave as I wanted. That is, show tooltip when hover, do not show tooltip for click. On other browsers and OS, When I click, the tooltip appear and stay as show. Even if i move the mouse to other buttons for hover. This is what I had:

    $('[data-toggle="tooltip"]').tooltip({placement: 'right', html: true}); 
    

    This is the fix:

    $('[data-toggle="tooltip"]').tooltip({placement: 'right', html: true, trigger: 'hover'}); 
    
    0 讨论(0)
提交回复
热议问题