Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Detecting and setting HTML-based tooltips

From: Create a Tooltip with jQuery

Video: Detecting and setting HTML-based tooltips

Now back in our HTML file, what we need to do here is add in those data attributes into the anchor link that's inside of the aside container. So let's scroll up here, let's find the aside container right here, inside there is an anchor link with a HTML-based tooltip link here. Let's come inside of the anchor tag, after the href attribute, hit space, we'll type data-tip-type, equals, two quotes. Inside of the quotes we'll put html, then we'll add another attribute, hit a space, data-tip-source, equals, two quotes, and instead of putting actual text here, what we're going to do is point to the id of the container we want to use.

Detecting and setting HTML-based tooltips

Now back in our HTML file, what we need to do here is add in those data attributes into the anchor link that's inside of the aside container. So let's scroll up here, let's find the aside container right here, inside there is an anchor link with a HTML-based tooltip link here. Let's come inside of the anchor tag, after the href attribute, hit space, we'll type data-tip-type, equals, two quotes. Inside of the quotes we'll put html, then we'll add another attribute, hit a space, data-tip-source, equals, two quotes, and instead of putting actual text here, what we're going to do is point to the id of the container we want to use.

So if I scroll down here, we created an ID down here called tooltip-sidebar. Let's select that name, copy to the clipboard, let's come up here and let's paste that in here. And then finally, let's come in here and add a class of tooltip. Let's choose Save, let's switchover to our JavaScript file. Now inside of the mouseover, we have our first detection here that's checking the data-tip-type and testing to see if it equals text. Let's copy this entire statement, let's hit few a Returns, still inside of the mouseover area, let's hit Paste and let's come in here and change text to html.

So the second if statement is testing the actual item that's being rolled over to see if the attribute data-tip-type is set to HTML, and if it is, we're going to run these instructions inside of here. So let's get our cursor in front of the first statement, let's hit two Returns, and above that what we're going to do is declare a new variable, we're going to type var elementToGet. We're going to set this equal to, two tick marks for string literal and a pound sign. Outside of the string literal, we're going to type a plus sign and then we're going to type dollar sign, parentheses, this, outside of the parentheses .attr, beginning and ending parentheses, semicolon.

Inside of the parentheses, two tick marks for string literal, and we want to go out and get the data-tip-source. So what this does is it goes out to the item that's being rolled over and we're checking the attribute data-tip-source, which in this case is actually the name of the ID where we put all of the HTML we want to have injected. We're adding a hash symbol here and putting these together or concatenating this into this single URL. It is going to give us something similar to what we're doing up here, where we're using jQuery to find a specific ID.

So once we've defined our variable elementToGet, on the next line we're going to declare a second variable. We're going to call this one newHTML and we're going to set that equal to, and then we're going to type dollar sign, beginning and ending parentheses, and we want to get this element, so let's copy that variable name, let's paste it down here, outside of the parentheses we're going to type .html, beginning and ending parentheses, then a semicolon. So we're going to go get whatever ID is specified in that link, we're going to pull all the HTML into the newHTML variable, and then on this line we're going to keep the tooltip container HTML, but instead of setting it to the value of the data-tip-source, let's remove that, and let's come in here and copy the newHTML variable, and let's paste that in there instead.

Let's save our document. Let's come back out to the browser and let's say Reload. Now over in our browser, we can rollover the HTML base tooltip, and then we can see the contents of the tooltip are now changing to all of the HTML that we put inside of that ID. Then I can go back to the text-based one and see just the text that is actually being pulled from that source attribute. So now that we are properly querying every one of the tooltip items and detecting whether they are text or HTML and populating the tooltip container, in the next movie we can now start to work on attaching the tooltip to where the mouse is.

Show transcript

This video is part of

Image for Create a Tooltip with jQuery
Create a Tooltip with jQuery

18 video lessons · 5124 viewers

Chris Converse
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Create a Tooltip with jQuery.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.