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.
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
$( document ).tooltip();
Step 2: The HTML Content
Add the following code in between your < body > < / body > tags. You can edit the content to suit your needs.
<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>
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.