Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now we'll need to add the data attributes to our sidebar link. Let's come back to our HTML file. Let's scroll up and let's find the link that's inside of the aside element, this element here, so we can see the href around the HTML-based tooltip. So after the href, let's hit a Space. Let's first add a class, tooltip, then a space. We'll add another attribute data-tip-type, equals, two quotes, the value we are going to set to html, then a space, data-tip-source, equals, two quotes.
And what we're going to do here, again since we can't put HTML as the value of this, let's scroll down on the page and let's find that id that we added. So we added an id called tooltip-sidebar. Let's copy that name. Let's scroll up and let's put that name as the data-tip-source. With that in place, save your file. Let's move over to the tooltip.js. So now we want to do a test for HTML typetips. Let's copy that entire conditional statement inside of the mouse move.
Let's hit a Return. Let's place this in here. Let's come down and change text to html, and then inside this conditional statement let's add some returns, and let's come up here and first declare a variable. So we are going to type var, elementsToGet. We're going to set that equal to, two tick marks for a string literal, then a pound sign. Outside the string literal we are going to hit a plus sign.
Then we need to get the value of the data-tip-source. So let's come down here and copy this statement down here. $(this).attrr('data-tip-source'). Let's copy that to the clipboard. Let's place that up here, then hit a semicolon. So this variable here, elementToGet, we're concatenating the pound sign plus the actual element name inside a data-tip-source. This together is to give is the id that we're looking for. On the next line we're going to declare another variable. Var equals newHTML.
We're going to set that equal to and then we're going to type $() and let's come up here and copy elementToGet. Let's paste that inside of the parentheses. Then outside of the parentheses we're going to .html();. Then lastly let's come over here and select newHTML. Let's copy that, and on the next line tooltip-container HTML, the values is going to be newHTML.
So again, what's happening here is if the tooltip that was rolled over has a data-tip-type of HTML, we want to find the data-tip-source which in these cases points to an HTML div on the page. So we want to find that and then declare a new variable of html and pull all of the HTML out of that id or that div container. Then we're going to populate that into the tooltip-container. So to test this let's choose File > Save. Let's come back to index.html.
Let's choose File > Save All and then File > Preview in Browser. Once in the Browser, hit Reload, and now if we come over here and roll over the HTML base tooltip notice that all of the HTML is now pulled from that hidden div and populated inside the tooltip-container. So this is the text-based tooltip and the HTML-based tooltip. So now that we're finding all of the tooltip classes and differentiating between text-based tips and HTML-based tips, in the next movie we can start working on positioning the tooltip to match where the cursor is.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97501 Viewers
61 Video lessons · 84744 Viewers
71 Video lessons · 68922 Viewers
56 Video lessons · 101373 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.
Your file was successfully uploaded.