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.
fouad masoud 5 Mar, 2009
Jeremy Mandle 5 Mar, 2009
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 5 Mar, 2009
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 5 Mar, 2009
Austin Siewert 5 Mar, 2009
Ozzy 5 Mar, 2009
nathanieL 5 Mar, 2009
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 5 Mar, 2009
Kadir GÜNAY 5 Mar, 2009
kk 5 Mar, 2009
Nick Rinylo 6 Mar, 2009
Hiren Modi 6 Mar, 2009
Andrea 6 Mar, 2009
fwolf 7 Mar, 2009
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 9 Mar, 2009
Grayden 9 Mar, 2009
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 11 Mar, 2009
Alex 12 Mar, 2009
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 12 Mar, 2009
Thanks
Tom 17 Mar, 2009
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 18 Mar, 2009
cssglobe 18 Mar, 2009
$("a#thumb").easyTooltip({
content: '<img src="http://mysite.com/myimage.jpg" alt="My Image" />'
});
Tom 18 Mar, 2009
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 19 Mar, 2009
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 19 Mar, 2009
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 19 Mar, 2009
I don't mean to be a smarty, but it's something you should really start to analyze.
Nice script.
Alexandre Broggio 20 Mar, 2009
vishal 24 Mar, 2009
Mike 26 Mar, 2009
vishal 4 Apr, 2009
mohammed 10 Apr, 2009
Odelon 22 Apr, 2009
Muy bueno, los trucos...
:) from Perú
Paul 22 Apr, 2009
Thanks in advance,
Paul
Jonathan Miller 4 May, 2009
Richard M 7 May, 2009
As I said, very new to this... Any help would be greatly aprpeciated.
Thanks again.
oakesy54 10 May, 2009
$(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 19 May, 2009
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 1 Jun, 2009
$(document).ready(function(){
$("a").easyTooltip();
$(".product1").easyTooltip();
$(".product1").easyTooltip({
tooltipId: "easyTooltip2",
useElement: "productDesc"
});
});
Gatto 10 Jun, 2009
boton 15 Jun, 2009
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 16 Jun, 2009