Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Detecting and setting HTML-based tooltips


From:

Create a Tooltip with jQuery

with Chris Converse

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.
please wait ...
Watch the Online Video Course Create a Tooltip with jQuery
54m 23s Intermediate Aug 28, 2012

Viewers: in countries Watching now:

Tooltips can greatly improve the usability of your web site by providing direction and cues to visitors. In this course, Chris Converse shows how to convert text or graphics into a mouse-sensitive tooltip. The tutorials demonstrate how to write the necessary HTML and activate the tooltip with jQuery, as well as add positioning and effects.

Topics include:
  • Saving web graphics from Photoshop
  • Creating the tooltip container
  • Adding the jQuery $(document).ready() and mouse events
  • Detecting and setting HTML-based tooltips
  • Attaching the tip container to the mouse
  • Setting the tooltip to fade in and out
  • Accounting for other CSS-positioned elements
Subjects:
Developer Web
Software:
jQuery
Author:
Chris Converse

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.

There are currently no FAQs about Create a Tooltip with jQuery.

 
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.

* Estimated file size

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

Upgrade to View Courses Offline

login

With our new Desktop App, Annual Premium Members can download courses for Internet-free viewing.

Upgrade Now

After upgrading, download Desktop App Here.

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 ?

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:

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Start your FREE 10-day trial

Begin learning software, business, and creative skills—anytime,
anywhere—with video instruction from recognized industry experts.
lynda.com provides
Unlimited access to over 4,000 courses—more than 100,000 video tutorials
Expert-led instruction
On-the-go learning. Watch from your computer, tablet, or mobile device. Switch back and forth as you choose.
Start Your FREE Trial Now
 

A trusted source for knowledge.

 

We provide training to more than 4 million people, and our members tell us that lynda.com helps them stay ahead of software updates, pick up brand-new skills, switch careers, land promotions, and explore new hobbies. What can we help you do?

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.