Reputation: 1923
I am using Bootstrap
and jQuery
to add some components to an app. I also want to add tooltips to some of those components. I am using jQuery
to display the tooltips in my index.html
page:
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
To use this, I would simply add data-toggle="tooltip" title="Tooltip goes here"
to the element tag on which I wanted to apply the tooltip.
I also have a button that launches a modal using data-toggle="modal", which comes from
Bootstrap`. I cannot simply use the following to add both the tooltip and the modal launch functionality:
<button
type="button"
class="btn"
data-toggle="tooltip"
data-target="#exampleModalCenter"
data-toogle="modal"
title="This launches the Program Form window"
>
Sign Up!
</button>
What's an easy way to get booth the tooltip and modal functionailty on this button?
Upvotes: 0
Views: 3226
Reputation: 1479
Call the bootstrap modal using Jquery click function will resolve your issue.
Snippet:
$(".btn").click(function() {
$('#exampleModal').modal('show');
});
$('[data-toggle="tooltip"]').tooltip()
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<div id="exampleModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row" style="margin-top:50px">
<div class="col text-center align-self-center">
<button type="button" class="btn btn-primary" data-toggle="tooltip" title="This launches the Program Form window">Sign Up!</button>
</div>
</div>
</div>
Upvotes: 1
Reputation: 11
You can try by adding click event with jquery for the modal funcionality, then the tooltip method.
For instance:
$(function () {
$('[data-toggle="tooltip"]').click(function(){
$("#myModal").modal();
});
$('[data-toggle="tooltip"]').tooltip();
});
Upvotes: 1