4 jQuery ToolTip Demo. Demo of how to add elements and get mouse coordinates
5 There is also a ToolTip plugin found at http://www.eyecon.ro/interface/,
6 which uses a CSS class to style the tooltip, but shows it below the input/anchor, rather than where the mouse is
13 $("a,input").ToolTipDemo('#fff');
19 bgcolour : Background colour
21 $.fn.ToolTipDemo = function(bgcolour)
26 if((!this.title && !this.alt) && !this.tooltipset) return;
27 // get mouse coordinates
28 // based on code from http://www.quirksmode.org/js/events_properties.html
29 var mouseX = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
30 var mouseY = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
33 bgcolour = bgcolour || "#eee";
34 // if there is no sibling after this one, or the next siblings className is not tooltipdemo
35 if(!this.nextSibling || this.nextSibling.className != "tooltipdemo")
37 // create a div and style it
38 var div = document.createElement("div");
41 border: "2px outset #ddd",
43 backgroundColor: bgcolour,
46 // add the title/alt attribute to it
47 .html((this.title || this.alt)).addClass("tooltipdemo");
52 this.parentNode.insertBefore(div, this.nextSibling);
56 this.parentNode.appendChild(div);
58 this.tooltipset = true;
60 $(this.nextSibling).show().css({left: mouseX + "px", top: mouseY + 3 + "px"});
65 if(this.nextSibling && this.nextSibling.className == "tooltipdemo")
67 $(this.nextSibling).hide();