Call Modal and Tooltip on the same data-toggle

Asked

Viewed 3,238 times

7

I have a button that calls a modal like this:

<button type="button" data-toggle="modal" data-target="#revisao>Revisao</button>

To call a Tooltip is used:

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

How to call Modal and Tooltip on the same button?

2 answers

8


Leave the same modal structure, include only a new data-type which will be your data-toogle, in my example, I used data-tt="tooltip" now just add the title and call no js.

Example:

$("[data-tt=tooltip]").tooltip();
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<br><br>

<a href="#myModal" role="button" class="btn btn-default" data-toggle="modal" data-target="#myModal" data-tt="tooltip" title="Olá Mundo!">Modal</a>


<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

  • 1

    Perfect and simple.

1

An option that does not involve changing the data-attribute name or javascript, is to wrap the element of Trigger (the button in the case) in another element that is inline, making it a type of "wrapper":

<span data-toggle="modal" data-target="#revisao">
    <button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="left" title="Tooltip on left">Revisao</button>
</span>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.