Tooltips using jQuery
March 1st, 2013 - No Comments »
In this snippet I am going to show you how to implement a nice Tooltip using jQuery. It is very simple
Step 1: The Scripts
Add the following code in between your < head > < / head > tags.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<head> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script> <script> $(function() { $( document ).tooltip(); }); </script> <style> label { display: inline-block; width: 5em; } </style> </head> |
Step 2: The HTML Content
Add the following code in between your < body > < / body > tags. You can edit the content to suit your needs.
|
1 2 3 4 5 6 7 8 9 10 11 |
<body> <p><a href="#" title="That's what this widget is">Tooltips</a> can be attached to any element. When you hover the element with your mouse, the title attribute is displayed in a little box next to the element, just like a native tooltip.</p> <p>But as it's not a native tooltip, it can be styled.</p> <p>Tooltips are also useful for form elements, to show some additional information in the context of each field.</p> <p><label for="age">Your age:</label><input id="age" title="We ask for your age only for statistical purposes." /></p> <p>Hover the field to see the tooltip.</p> </body> |
The title=”" attribute is the important part with this snippet, whatever you put inside it will be the content that will show in your tooltips.
…and there you have it, a quick and simple way to incorporate tooltips into your website.
Related posts:








