Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make bootstrap tooltip remain visible till the link is clicked

I have a link which I am going to use as notification when a user has some new notification I am going to notify the user by showing a tooltip(twitter bootstrap tooltip). What I want to achieve is, that tooltip should remain visible till the user clicks the link. once the user clicks the link, the tooltip should destroy. this is what I have till now, http://jsfiddle.net/testtracker/QsYPv/

HTML

<p><a href="#" rel="tooltip" data-original-title="you have 2 notifications">Notification</a>.</p>​ 

JavaScript

$('p a').tooltip({placement: 'bottom'}).tooltip('show');​ 

What's happening there is, tooltip stays visible till you hover it, and takes its default behaviour (show on hover) once you hover it.

I hope I have given proper info and cleared what I want to do.

like image 402
vikas devde Avatar asked Oct 22 '12 16:10

vikas devde


People also ask

How do I make my tooltip always visible?

Single element To make an element display its tooltip permanently, we use its showTooltipOn property. To make tooltip always be shown, set it to "always" .

Are Bootstrap tooltips accessible?

As you may know, the Twitter bootstrap tooltips are not accessible (I.E. they are not being read by screen readers).

How do I show tooltip in bootstrap?

How To Create a Tooltip. To create a tooltip, add the data-toggle="tooltip" attribute to an element. Note: Tooltips must be initialized with jQuery: select the specified element and call the tooltip() method.

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

Here is the solution http://jsfiddle.net/testtracker/QsYPv/8/

Added the option "trigger"

$('p a').tooltip({placement: 'bottom',trigger: 'manual'}).tooltip('show'); 

then, with this line

$('p a').on('click',function(){$(this).tooltip('destroy');}); 

destroy tooltip on click.

like image 188
vikas devde Avatar answered Oct 04 '22 02:10

vikas devde


You can add a variable to trigger off the mouseleave event to re-show the tooltip, and then as you said in your comment, just destroy the tooltip when clicked, so it doesn't show when you mouseover again:

var clickedNotify = false; $('p a').tooltip({placement: 'bottom'}).tooltip('show'); $('p a').mouseleave(function() { if (!clickedNotify) { $('p a').tooltip({placement: 'bottom'}).tooltip('show'); } }); $('p a').click(function() { clickedNotify = true; $(this).tooltip('destroy'); }); 

This way, the tooltip is always shown, even after a mouseleave, until the link is clicked. After the link is clicked, the tooltip is destroyed, and still won't generate javascript errors on the page on mouseleave.

like image 35
Nathan Wheeler Avatar answered Oct 04 '22 00:10

Nathan Wheeler