Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set multiple data-toggle for a link in bootstrap?

I have a link and I want to set a bootstrap tooltip for it and aI want it to show a bootstrap modal too. To show a modal the code is this:

<a href="#myModal" role="button" data-toggle="modal">Show</a>

And the following would make a bootstrap tooltip:

<a data-placement="right" data-toggle="tooltip" rel="tooltip" data-original-title='Hello' href="#"></a>

Now how to combine it.Combine means having a link that shows modal and has a bootstrap tooltip too?

like image 854
Hamid Reza Avatar asked Aug 02 '13 12:08

Hamid Reza


People also ask

How do I use data toggle in Bootstrap?

Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class in.

How do I create a toggle button in Bootstrap?

Add data-toggle="buttons" to a . btn-group containing those modified buttons to enable their toggling behavior via JavaScript and add . btn-group-toggle to style the <input> s within your buttons. Note that you can create single input-powered buttons or groups of them.

What is data toggle attribute in Bootstrap?

The data-toggle is an HTML-5 data attribute defined in Bootstrap. The advantage of using this is that, you can select a class or an id and hook up the element with a particular widget.

What is data toggle and data target in Bootstrap?

The toggle tells Bootstrap what to do and the target tells Bootstrap which element is going to open. So whenever a link like that is clicked, a modal with an id of “basicModal” will appear.


6 Answers

I found the issue:

<a href="#myModal" role="button" data-toggle="modal" rel="tooltip" data-original-title='Hello'>Show</a>

Thats all.

like image 83
Hamid Reza Avatar answered Oct 20 '22 00:10

Hamid Reza


I would rather use a wrapping element like this:

<span data-placement="right" data-toggle="tooltip" title="Hello">
    <a href="#myModal" role="button" data-toggle="modal">Show</a>
</span>

This seems more straightforward to me. See this bootply: http://www.bootply.com/zqJRSAjSuQ

like image 42
F.L. Avatar answered Oct 19 '22 22:10

F.L.


you dont need use data-toggle for tooltip, you can change to you want, like data-tt for example:

<a href="#myModal" role="button" data-toggle="modal" data-tt="tooltip" title="hi">Show</a>

And initialize in javascript:

$("[data-tt=tooltip]").tooltip();

JsFiddle

like image 21
Marcos Furquim Avatar answered Oct 20 '22 00:10

Marcos Furquim


U may also need to to initialize it : I needed to initialize it at bottom of page.

        $("[rel='tooltip']").tooltip();
like image 40
Deepak Yadav Avatar answered Oct 20 '22 00:10

Deepak Yadav


Add a data attribute to the element:

<a data-toggle="modal" data-hover="tooltip" title="Click to Open" data-placement="right" href="#"></a>

And initialize in javascript:

$("[data-hover='tooltip']").tooltip();
like image 41
mintedsky Avatar answered Oct 20 '22 00:10

mintedsky


You might want to consider using a div instead of a span element when the tooltip is misplaced ...

Based on F.L.'s answer, this worked for me:

<div data-placement="right" data-toggle="tooltip" title="Hello">
    <a href="#myModal" role="button" data-toggle="modal">Show</a>
</div>
like image 21
Gerardo Navarro Suarez Avatar answered Oct 19 '22 22:10

Gerardo Navarro Suarez