Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap: Collapse and Tooltip together

Tags:

I want to know if its possible to have tooltip on a collapse anchor tag. The code which is use for collapse is:

<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Data</a> 

It works fine but now I want to add a tooltip to it. So I changed the code to:

<a data-toggle="collapse tooltip" title ="Tooltip Message" data-parent="#accordion" href="#collapseOne">Data</a> 

Now it shows the tooltip but the collapse function does not work. What changes I have to do so that both functionality works. I know the text of anchor tag can actually show the message I want to use as tooltip message but just want to know if its possible to have both functionality together

like image 966
neophyte Avatar asked Jun 13 '14 08:06

neophyte


People also ask

How do I create a collapsible menu in Bootstrap?

Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.

How do I add tooltip to disabled button?

To trigger tooltip on disabled button by wraping them in <span> span tag and <div> div tag and then adding 'data-toggle','data-placement' and 'title' attributes to it along with its values respectively.

How do I show tooltip without mouseover?

You want to show tooltip without mouseover? Then it's not called tooltip. Just use a usercontrol or even a textblock to do it. You position this control to where you want it and set visibility / or opacity to control how long you want to show it.

How do I create a toggle div in Bootstrap?

To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element. Then add the data-target="#id" attribute to connect the button with the collapsible content (<div id="demo">).


2 Answers

From the Bootstrap Javascript overview page:

Component data attributes

Don't use data attributes from multiple plugins on the same element. For example, a button cannot both have a tooltip and toggle a modal. To accomplish this, use a wrapping element.

Try this:

<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">   <span data-toggle="tooltip" title="Tooltip Message">Data<span> </a> 
like image 154
awe Avatar answered Sep 22 '22 16:09

awe


Another solution is to change trigger for tooltip. Default trigger is:

$(function () {   $('[data-toggle="tooltip"]').tooltip() }) 

Which will work like this:

<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">Tooltip on bottom</button> 

But you can change it to:

$(function () {   $('[data-tooltip="true"]').tooltip() }) 

Which will work like this:

<button type="button" class="btn btn-default" data-tooltip="true" data-placement="bottom" title="Tooltip on bottom">Tooltip on bottom</button> 
like image 25
Rikard Avatar answered Sep 20 '22 16:09

Rikard