I love the simplicity of using (and more important re-using) jQuery plugins. So I decided to release yet another plugin that came from my personal need - jQuery tooltip. I already claimed this to be the simplest tooltip ever. I made some modifications to it so now has some extra features.
Overview
By default this plugin will read the title attribute of the element and convert it into fade-in tooltip that you can style any way you want. Important note, it doesn't have to be an anchor tag. You can apply this script to any element(s) you want.
The one big thing that makes this different from my first version is that you are now allowed to put custom content, any html content you want - images, long paragraphs, link lists... anything. If you hate writing HTML code inside a JavaScript variable, this plugin allows you to use inner HTML from any element on the page. It means that you can write HTML directly on the page, as you normally do, hide that element with CSS and have it appear as a tooltip on mouse over. Take a look at the demos for more info.
Options
- xOffset - Offset to the left from the cursor (in pixels). Default setting is 10.
- yOffset - Offset to the top from the cursor (in pixels). Default setting is 25.
- tooltipId - Use this if you want to assign custom id to your tooltip. Also, if you have multiple tooltips on one page and you want to style them differently, use ID's to assing different css definitions. Default setting is "easyTooltip".
- clickRemove - By default tooltip dissapears once you rool out of the element. Using this options you can remove tooltip by clicking on the element. Default setting for this option is false.
- content - By default Easy Tooltip displays title attribute of an element. Use this option to send a custom content to the tooltip. Default setting for this option is "" (empty).
- useElement - If you'd like to display more complex HTML in your tooltip and yet you hate writing it inside a content option, you can use a certain element's inner HTML. Best way to use this option is to create a static HTML element, hide it with css, use it's id when setting up the plugin (take a look at the 3rd demo)
Demos
Take a look at these demos and you will see how simple it is to use this plugin.
Designer, developer and a passionate standardista. Long time web professional with huge experience in all types of front-end work. Founder of Css Globe and creator of
fouad masoud on 5 Mar, 2009 wrote:
Jeremy Mandle on 5 Mar, 2009 wrote:
I've been "hacking" away at learning jQuery as of late and will put this simple, elegant tooltip plugin to use very soon. Bravo Alen!
Ed Salt on 5 Mar, 2009 wrote:
What would be perfect would be if the script could detect whether the tooltip is appearing beyond the edges of the visible window, and change the offsets accordingly ;)
Jhon Doe on 5 Mar, 2009 wrote:
Austin Siewert on 5 Mar, 2009 wrote:
Ozzy on 5 Mar, 2009 wrote:
nathanieL on 5 Mar, 2009 wrote:
Would just like to echo Ed Salt
"What would be perfect would be if the script could detect whether the tooltip is appearing beyond the edges of the visible window, and change the offsets accordingly"
cssglobe on 5 Mar, 2009 wrote:
Kadir GÜNAY on 5 Mar, 2009 wrote:
kk on 5 Mar, 2009 wrote:
Nick Rinylo on 6 Mar, 2009 wrote:
Hiren Modi on 6 Mar, 2009 wrote:
Andrea on 6 Mar, 2009 wrote:
fwolf on 7 Mar, 2009 wrote:
In your example, you've got an DIV-container with the ID "item", which gets assigned using <code>useElement: "item"</code>
To improve the logical structure I would call it "useID" instead, because it's obviously using that and NOT an HTML element, as one would think of by reading this option name.
cu, w0lf.
Adam Fisk on 9 Mar, 2009 wrote:
Grayden on 9 Mar, 2009 wrote:
My next question is me probably asking too much but how Could I control the tip to switch its position to the left or right side of the cursor depending on the browser window?
Thanks so much for any advice you can give me.
shpyo on 11 Mar, 2009 wrote:
Alex on 12 Mar, 2009 wrote:
I really like this. But i am unable to use it for an image map especially the area tag in IE. Can you confirm if it works at your end.
Thanks
Alex
Alex on 12 Mar, 2009 wrote:
Thanks
Tom on 17 Mar, 2009 wrote:
One question - can this one be used to preview an image like your old one did? I think I may be able to use the 'element' example, but couldn't figure out how to include the image source.
Any hint would be great.
Thanks again!
Martin Miranda on 18 Mar, 2009 wrote:
cssglobe on 18 Mar, 2009 wrote:
$("a#thumb").easyTooltip({
content: '<img src="http://mysite.com/myimage.jpg" alt="My Image" />'
});
Tom on 18 Mar, 2009 wrote:
What if there are more that one image on the page? I tried using
content: '<img src="'+this.href+'" alt="My Image" />'
but that doesn't seem to work.
Thanks again
Nick on 19 Mar, 2009 wrote:
Add this line into easyTooltip.js
content = (options.func != "") ? eval(options.func)() : content;
just below the other content lines. Now you can call the tooltip like so...
$(".event-title").easyTooltip({
func: function() {return "hello world";}
})
Thanks for the great plugin!
Kris on 19 Mar, 2009 wrote:
Please add your site at http://www.sweebs.com. Sweebs.com is a place where other people can find you among the best sites on the internet!
Its just started and we are collecting the best found on the net! We will be delighted to have you in the sweebs listings.
Regards
Kris
Matt on 19 Mar, 2009 wrote:
I don't mean to be a smarty, but it's something you should really start to analyze.
Nice script.
Alexandre Broggio on 20 Mar, 2009 wrote:
vishal on 24 Mar, 2009 wrote:
Mike on 26 Mar, 2009 wrote:
vishal on 4 Apr, 2009 wrote:
mohammed on 10 Apr, 2009 wrote:
Odelon on 22 Apr, 2009 wrote:
Muy bueno, los trucos...
:) from Perú
Paul on 22 Apr, 2009 wrote:
Thanks in advance,
Paul
Jonathan Miller on 4 May, 2009 wrote:
Richard M on 7 May, 2009 wrote:
As I said, very new to this... Any help would be greatly aprpeciated.
Thanks again.
oakesy54 on 10 May, 2009 wrote:
$(this).mouseover = function() { hover's second parameter function logic };
Hope this helps anyone who wants to use this cool little plugin for IE area elements :)
Karl
Andy Barnes on 19 May, 2009 wrote:
Under XHTML spec ID attributes should always be unique. This is easy to change within your example - just replace the anchor's id with a class and then change the initialisation to:
$("a.mylink").easyTooltip();
^ using dot instead of # still works fine
On another note I'm also experiencing an issue with (shock!) IE6 where nearby input elements appear on top of the popped up tooltip. Not sure if anyone knows a fix?
Otherwise a great and easy plugin - thank you!
asad on 1 Jun, 2009 wrote:
$(document).ready(function(){
$("a").easyTooltip();
$(".product1").easyTooltip();
$(".product1").easyTooltip({
tooltipId: "easyTooltip2",
useElement: "productDesc"
});
});
Gatto on 10 Jun, 2009 wrote:
boton on 15 Jun, 2009 wrote:
I have a problem updating data from ajax (including plugin content) my solution (for no append various same id):
change
$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");
for
if ($('#'+options.tooltipId).length == 0) $("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");
else $('#'+options.tooltipId).text(content);
kabin on 16 Jun, 2009 wrote: