Exercise 16 - Tooltips and Modals
Exercise 16 - Tooltips and Modals
Add modals that are revealed when the user clicks on a link or a button in the
web page.
Adding a Tooltip
Let us now switch to the index.html page. We will now add a tooltip to this page.
The tooltip will be added to the "Reserve Table" button that is in the jumbotron.
We will update the <a> tag for the button as follows:
As you can see from the code, we add a data-toggle, data-placement and a title
attribute to the <a> tag in order to introduce a tooltip.
<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
1
</script>
This script is added right after the line that imports the bootstrap.min.js file.
Adding a Modal
In the next step we introduce the modal to the web page. To set up the modal,
add the following code right after the navbar at the top of the page.
2
</div>
<div class="col-sm-auto">
<div class="form-check">
<input class="form-check-input" type="checkbox">
<label class="form-check-label"> Remember me
</label>
</div>
</div>
</div>
<div class="form-row">
<button type="button" class="btn btn-secondary btn-sm ml-
auto" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary btn-sm ml-
1">Sign in</button>
</div>
</form>
</div>
</div>
</div>
</div>
Next we introduce another link on the right side of the navbar in order to trigger
the display of the modal. To do this, add the following code in the navbar after
the </ul>:
<span class="navbar-text">
<a data-toggle="modal" data-target="#loginModal">
<span class="fa fa-sign-in"></span> Login</a>
</span>
3
We are introducing another link to the right of the navbar using the navbar-text. This
contains a link with an <a> tag with the data-toggle="modal" and data-
target="#loginModal" attributes.
Save all the changes and do a Git commit with the message "Tooltip and
Modal".
Conclusions
In this exercise we explored tooltips and modals as two ways of revealing content
for the user upon clicking on a button or a link.