Bootstrap 5 Crash Course Tutorial #15 - Tooltips

Net Ninja · Beginner ·🌐 Frontend Engineering ·5y ago

Key Takeaways

Demonstrates Bootstrap 5 tooltips component

Full Transcript

all right then gang so the next component we're going to look at is the tooltip component and this is a little information bubble that pops up with more information when you hover over something you see them quite a lot in forms to explain form fields so you can see them in action if you hover over these buttons and notice how it appears in different places so to the top the side the bottom etc so you can easily configure this with a date attribute now they're really easy to set up but they do require one extra step a small amount of javascript is required to initialize any tool tips you add to your page so let's take a look at how to do it all right so we're going to place a couple of tooltips on this page three in total the first one is gonna be on this book just so i can show you how they work and then after that we'll come down to the form and we're gonna place a couple of icons at the end of these two inputs right here and when we hover over those icons we're gonna show a tooltip there as well so let's start at the top on the image so it's in the intro section at the bottom of that we have an image right here we're going to surround that with a tooltip now the way we do this is by making a span first of all and i'm going to take the image and put it inside that span sack now i'm going to give this a class and that class is going to be tt now this is not a bootstrap class this is just a class i've made up tt for tooltip so that when we start to use javascript to implement the tooltips to trigger them if you like it's going to look for anything with a class of tt you can call it something different if you wish anyway but by the way don't call it tool tip because bootstrap is going to use that under the hood when it starts to work its magic in the javascript so anything else all right then so after that i'm also going to give this a data attribute and that data attribute is to say where we want this tool tip to show do we want it at the top when you hover over to the side or at the bottom etc so let's say data hyphen bootstrap hyphen placement like so and set that equal to bottom in this case and then finally we just need a title attribute and in here is the text that we're going to show when a user hovers over this image so the information in the tooltip so i'm just going to paste in a sentence right here oops not that one we don't want that that's for the form okay so we'll just say net ninja book cover all right so let me try this out at the minute if i save it and hover over the book nothing is gonna work and that is because remember i said that in order for this to work we have to add a little bit of javascript so there are just a handful of different components in bootstrap that when you use them you have to trigger them or start them with a bit of javascript it's not hard to do just scroll down to the end of the page inside the body at the end of the script right here after that one we're going to paste in another script dead simple all i do is create a constant called tooltips and i set it equal to document.queryselect all and i grab anything on the page with a class of tt remember that was the class i gave the spam tag so we have then a collection of elements because there might be three or four tooltips on the page right they're all now going to be stored inside tooltips then we cycle through that collection using a for each and for each tool tip which i refer to as t we fire a function and all we do is create a new bootstrap tooltip and we pass in the element and that creates it for us and that takes care of everything so that's all we have to do and now we can add as many tooltips on the page as we like because this is going to find all of them as long as they have that class of tt they're going to work so if i save this now and come to the top and hover over now we can see that tooltip and you can see that the arrow is at the top and the message is at the bottom that's because we said the placement was at the bottom all right cool so now let's add some tool tips in the form so i've created two comments where we're going to add these this is the first input and it's going to be inside the input group so all we're going to do is create another input group text like this so let me copy that and paste it down here and this icon is going to be something different we want it to be some kind of question mark so i'm going to use question hyphen circle like so so that's a question mark in a circle and also i'm going to give this a class of text muted okay so that's the icon and if we take a look at this we're going to see that if i scroll down here we can see that now i want to implement the tooltip so that when we hover over this we see that tooltip so we need to surround this icon with the tooltip so i'm going to say span right here and again i need to give this a class of tt so that our javascript picks it up i'll take the closing span and place it after the icon like so and then inside here we need to say where the placement is so data hyphen bootstrap hyphen placement and again that's going to be equal to the bottom you can use a different value if you want and then the title which i'm going to set equal to the thing i pasted before oops it's gone now from a clipboard let me just grab it again paste it in so enter an email address we can reply to okay so before we test this out i'm just going to copy all of this right here and i'm going to place it down here where we have this tooltip as well so again it's inside the input group for the second input and we're going to use the same icon this time we're just saying here pretty self explanatory can i spell this explanatory really dot dot all right so if we now hover over this one then we can see enter an email we can reply to and for the name pretty self-explanatory really awesome so there we go my friends that's how we create tooltips dead simple just create the span with any class except for tooltip and then create the placement the title which is the text inside the tooltip and then surround whatever element you want the tooltip to be for and then finally in the script just create a script like this to trigger them

Original Description

🐱‍👤 View this course in full now - without ads - on Net Ninja Pro: https://netninja.dev/p/bootstrap-5-crash-course 🐱‍💻 Access the course files on GitHub: https://github.com/iamshaunjp/bootstrap-5-tutorial 🐱‍💻 HTML & CSS Crash Course: https://www.youtube.com/watch?v=hu-q2zYwEYs&list=PL4cUxeGkcC9ivBf_eKCPIAYXWzLlPAm6G 🐱‍💻 Node.js Crash Course: https://www.youtube.com/playlist?list=PL4cUxeGkcC9gcy9lrvMJ75z9maRw4byYp 🐱‍💻 SASS Crash Course: https://www.youtube.com/watch?v=St5B7hnMLjg&list=PL4cUxeGkcC9iEwigam3gTjU_7IA3W2WZA 🐱‍💻 VS Code - https://code.visualstudio.com/ 🐱‍💻 Bootstrap 5 Docs - https://getbootstrap.com/docs/5.0/getting-started/download/ 🐱‍💻 Social Links: Facebook - https://www.facebook.com/thenetninjauk Twitter - https://twitter.com/thenetninjauk Instagram - https://www.instagram.com/thenetninja/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

Related Reads

📰
Next.js vs Remix vs SvelteKit: Which Framework Should You Learn?
Learn how to choose between Next.js, Remix, and SvelteKit for your next project and why it matters for your career as a developer
Dev.to · Etrit Neziri
📰
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Prepare for a frontend developer interview with Capgemini by reviewing JavaScript fundamentals and practicing common interview questions
Medium · JavaScript
📰
10 Frontend Developer Tools to Boost Productivity in 2026
Boost frontend productivity with 10 essential tools for modern web app development
Medium · Programming
📰
10 Frontend Developer Tools to Boost Productivity in 2026
Boost frontend productivity with top 10 developer tools in 2026
Medium · JavaScript
Up next
The masks we wear | Zora Krstić | TEDxLuxembourgCity
TEDx Talks
Watch →