Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap button tooltip hide on click

On my site I have some buttons. When a user clicks the button, a modal opens. When a user hovers the button, a tooltip is shown.

Is use this code:

<button type="button" rel="tooltip" title="Tooltip content" class="btn btn-sm btn-default" data-toggle="modal" data-target="#DeleteUserModal">   <span class="glyphicon glyphicon-remove"></span> </button>  <div>modal</div>  <script> $(document).ready(function(){   $('[rel="tooltip"]').tooltip(); }); </script> 

This works, but the only problem is that the tooltip stays visible after the button is clicked, and the modal is shown. As soon as the modal is closed, the tooltip is hidden again.

How to prevent this? I only want the tooltip to be shown on hover, and not all the time when the related modal is visible.

like image 487
Mbrouwer88 Avatar asked Jan 29 '16 08:01

Mbrouwer88


People also ask

How do I close a tooltip?

The span element will contain a tooltip div with a little html (image and link). Tooltip should be opened when clicked on the span element and closed when clicked outside of it or outside of the tooltip.

How do I change the tooltip position in bootstrap?

How to position the tooltip - auto | top | bottom | left | right. When auto is specified, it will dynamically reorient the tooltip. When a function is used to determine the placement, it is called with the tooltip DOM node as its first argument and the triggering element DOM node as its second.


2 Answers

Fixed it by using.

$(document).ready(function(){     $('[rel=tooltip]').tooltip({ trigger: "hover" }); }); 

The problem was that focus stays on the button when the modal is open. Changing the trigger to hover solves the problem.

like image 147
Mbrouwer88 Avatar answered Sep 28 '22 02:09

Mbrouwer88


For your whole project hide tooltip

   $(document).ready(function(){        $('[data-toggle="tooltip"]').click(function () {           $('[data-toggle="tooltip"]').tooltip("hide");         });    }); 
like image 25
Adnan Ahmad Avatar answered Sep 28 '22 03:09

Adnan Ahmad