Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So the first thing we want to do in the mouseover event is to detect what type of tooltip we're actually looking at. So we're going to open this up a little bit inside of mouseover and we're going to start by typing an if statement, so we're going to type if, beginning and ending parentheses, then beginning and ending bracket, let's split the brackets open. Let's come up inside of the parentheses and what we're going to do is test the actual item that was rolled over. So since we're inside of whatever tooltip was triggered, we can come in here and type dollar sign, parentheses, and the word this inside of the parentheses, that's going to return whatever item on the HTML has a tooltip class and was actually rolled over by somebody's mouse.
So for that object, after this, we're going to type .attr for attribute, put in our parentheses, two tick marks inside for string literal. We want to look at the actual attribute called data-tip-type, outside of the parentheses hit Space, two equal signs to test the absolute equality, then a space, two tick marks for a string literal, and then type in the word text.
So what we're doing is any item that's rolled over with a tooltip class, we're going to check the attribute of that object and see if the data-tip-type was text. If it is, we're going to put our instructions inside of this if statement. So what we're going to do here is we're going to target the tooltip container, dollar sign, parentheses, tick marks inside for string literal, pound sign, because the tooltip container is an ID, tooltip_container, outside of the parentheses .html, parentheses, then a semicolon.
Now the value of the HTML is going to be the attribute of the same object we rolled over called data-tip-source. So inside of the parentheses for HTML, let's start with dollar sign, parentheses, this, outside of the parentheses, attr for attribute, inside of the parentheses, two tick marks for string literal, data-tip-source. Now to test this let's choose File > Save, let's come back out to our project files, let's reload this in a browser and then when I come over here and rollover the text based tooltip, once I rollover, you'll see that the text actually changed down here to this is a text for tooltip.
To see that again, I'll hit Reload. We have This is my tooltip, which is the default text we put in. Come over to the rollover and then it changes to this a text for tooltip. So now we're properly targeting every item that has the class of tooltip and we're able to pick out the data to see what type it is and pull out the source to populate the container with that particular data. So now that we have text-type-tooltips ready. In the next movie, we'll start building our structure for the HTML based tooltips.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 93614 Viewers
82 Video lessons · 104403 Viewers
71 Video lessons · 76587 Viewers
56 Video lessons · 107905 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.