Click here to Skip to main content
Click here to Skip to main content

A Simple Tooltip With Images And Text

By , 16 Sep 2007
 
Screenshot - With image and Text.jpg

Introduction

As web programmers, we need to show tooltips often in our pages, but not in an old fashioned way. Tooltips should be appealing and subtle to the page layout and design.

Most of the time, we go for available open source scripts which are free. I was also doing the same until I decided to write a simple one when I realized that customizing a free snippet took more time.

Background

A little bit of JavaScript, HTML and CSS experience will help you in modifying the script to suit your needs.

Using the code

Writing a tooltip is quite simple. This is a simple tooltip for our web pages with minimal code. Images, text and HTML code can be shown inside the tooltip.

First, we have to define a div which is our tooltip that we are going to use for our tooltip. Using a div will help us to show images, HTML code etc. inside a tooltip.

We can define the styles of the tooltip like transparency, font etc.

Once the tooltip div is OK, we have to add some attributes/events to the elements for which we are going to use this tooltip.

For example, I want to show a tooltip with text only for a span. Then I've to add the following to the span.

  1. onmouseover
  2. onmouseout

These two events are used to show the tooltips while the mouse is over the span and hide the tooltip when the mouse is out of the span.

<span onMouseOver="toolTip('simple Tooltip Text here')" onMouseOut="toolTip()"
    class="Text">Simple Tooltip</span> 

For tooltip function, there are three parameters to be passed. The first parameter is mandatory, in which we are going to pass the text to be shown for the tooltip.

The second and third parameters are optional. They are the foreground color and background color respectively. If these two parameters are omitted, then the default colors will be used.

To show an image inside or show some formatted message with HTML markup, we can first form an HTML string and then pass it to the tooltip function. That's all.

The tooltip will have the formatted text and image. There is nothing special to code for this. The div tag does everything that we need to show (images, HTML string etc).

<span
    onMouseOver="show()" onMouseOut="toolTip()"
    class="Text">Tooltip with Images and Text</span> 

For formatting, I'm using a separate function show() to avoid confusion while using an HTML string and maintain readability. Inside show(), we can format the string, add text, image etc. needed for the tooltip. You can use your own function or use inline code in the onmouseover = "".

function show()
{
    s = '<table width="100%" cellspacing="2" cellpadding="0" border="0">';
    s += '<tr><td><img src="http://upload.wikimedia.org/wikipedia/meta/2/2a/
        Nohat-logo-nowords-bgwhite-200px.jpg" border="0"/> </td>
        <td valign="top">WikiPedia</td></tr>'; 
    s += '<tr><td colspan="2" class="Text">
    <hr/>this is a test for simple tooltip. 
    <br/>You can add text and images to the tooltip</td></tr>';
    s += '</table>'
    toolTip(s)
}

Now everything is ready. We are going to look into how the tooltip is being shown in the mouse position.

Whenever the mouse is moved inside the document, we are detecting the event using document.onmousemove = moveToMousePos;

This will place the tooltip in the mouse's current position. The moveToMousePos function will detect the mouse coordinates and set the tooltip div's left and top positions. So when the mouse is over the span, we want to show the tooltip, then the tooltip's display property will be set to block and when out, display property is set to none.

Screenshot With Colors Set

Screenshot Text only

Note

  1. We can set the font styles and opacity of the tooltip using the CSS class
    .toolTip 
    {
        font-family<span class="code-none">: Verdana, Arial, Sans-serif, 'Times New Roman'<span class="code-none">;
        font-size<span class="code-none">: 8pt<span class="code-none">;        
        filter<span class="code-none">:alpha(opacity=80)<span class="code-none">;
        -moz-opacity<span class="code-none">: 0.8<span class="code-none">;
        opacity<span class="code-none">: 0.8<span class="code-none">;
        /* comment the above 3 lines if you don't want transparency*/
    <span class="code-none">} </span></span></
  2. We can insert HTML with tables for better formatted output/look for the tooltip. But don't include HTML, body tags.
  3. We can add this tooltip for any HTML element. In this example I've used the span tag.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Kumar Sundaram
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionZ-indexmemberTim Ramich9 Oct '12 - 10:01 
I can't get this to be on top of other divs. The tooltip div falls under my body div. My header and footer div have a higher z-index than the body div.
Questionlocation of tooltip changesmemberMember 37514835 Apr '11 - 0:33 
I'm trying the code. It works just fine with just a few (3 or so) images as long as they remain at the top of the page.
When I have a page through which you have to scroll, the images go to the top of the page and are no longer connected with the mouseover link. By the time I get to the bottom of a long page, i can no longer see the tool tip.
Is there a fix to this?
AnswerRe: location of tooltip changesmemberScott Wolfington7 Jan '12 - 7:57 
I have this same issue. Anyone figure out a fix for it yet?
GeneralRe: location of tooltip changesmemberScott Wolfington7 Jan '12 - 8:03 
It doesn't seem to be a problem in Firefox or Chrome. It's an issue in IE7 though.
GeneralRe: location of tooltip changesmemberScott Wolfington7 Jan '12 - 8:13 
I fixed it. In the moveToMousePos function, change the else statement to the following:
 
x = event.x + document.body.scrollLeft + document.documentElement.scrollLeft;
y = event.y + document.body.scrollTop + document.documentElement.scrollTop;
 
That seems to have fixed the issue.
QuestionHow to assign Tooltip Text at run-time?memberadamnguyen1 Apr '10 - 11:02 
This is great Tooltip Script !
 
I'm using ASP.NET 3.5 and C#.
Please instruct me how to assign Tooltip TEXT at runtime ?
The Tooltip TEXT I will get is from Database Table (for example).
 
I would appreciate it, if you will send me sort code in C# example of assigning Tooltip TEXT at runtime.
 
Please send to my current email address:
 
adam.d.nguyen@verizon.com
 
Thank you;
Adam
NewsThanksmembersherazkhan11519 Nov '09 - 23:15 
your code help me a lot so
i am very thankful to you
QuestionHow i can use this Code in Server Side ......memberketan d patel11 Jun '09 - 19:55 
Hii Frd.
 
I am using tooltips in my Project in Gridview.It's Working Fine but After Some Content Template Added It's not Working.
 
I want to Now Implement your Code How i can Use this Code in Server Side. ?
 
I have try but not Success.
 
Thanks.
 
http://dotnet-magic.blogspot.com/

Questioncan I insert an image within a rounded cornered box? - and soem formatted text ?memberJohn Donahue5 Oct '07 - 10:52 
Hi.. Thanks for the code. I wish I could attach an image here .. but I guess I cant.. anyhow.. I have a special need.. that goes like this:
 
1. insert an image that shows up within a rectangle.
2. the rectangle has rounded corners .. [ i.e. not straight]
3. within the rectangle as mentioned in 1 above- I have to display a small image - adjacent to which I have some text]
 

Please let me know if:
[a] what I want done is possible
[b] if possible, what would be my options?
[c] Can I send you an email - with my tool tip text? - I do not have your email address..
 
PS: one of our coders - Manish, has been using your fabulous code - for the job.. I am the founder/CEO - in other words , technically illeterate Smile | :) .. I would be obliged if you would help... as you have already done..
 
thanks a ton..
 
regards
ajay


AnswerRe: can I insert an image within a rounded cornered box? - and soem formatted text ?memberKumar Sundaram7 Oct '07 - 15:16 
Hi Ajay,
Please send an email to me with the tooltip text to guyfromchennai at
g - m - a - i - l - d - o - t
- c - o - m .
 
You want to show an image inside an rounded rectangle within the tootip ? not a problem. if you can send me the image and tooltip text (if possible with the rounded corner images also)
Will look into that and let you know.
 


 
Regards,
Kumar S
GeneralThanksmemberManishTech28 Sep '07 - 19:35 
Hi,
Thanks you have solved my big problem. It is a wonderful code.
I am so dumb how I forget to declare a div.But anyway Thank you very much for your help and code.
 
Thanks & Regards
ManishSmile | :)

GeneralThe way i used your codememberManishTech26 Sep '07 - 20:27 
Hi,
Thanks for your precious time.Here is the code.Please solve my problem.
 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
      <title>Untitled Page</title>
      <style type="text/css">
.Text{
            font-family: Verdana, Arial, Sans-serif, 'Times New Roman';
            font-size: 8pt;
            font-weight: normal;
            font-style: normal;
            color: #333333;
            text-decoration: none;
}
 
.toolTip {
            font-family: Verdana, Arial, Sans-serif, 'Times New Roman';
            font-size: 8pt;
            filter:alpha(opacity=80);
            -moz-opacity: 0.8;
            opacity: 0.8;
            /* comment the above 3 line if you don't want transparency*/
}
 
</style>
     
<script language="javascript" defer="false" >
      browser detection
      var agt=navigator.userAgent.toLowerCase();
      var is_major = parseInt(navigator.appVersion);
      var is_minor = parseFloat(navigator.appVersion);
 
      var is_nav   = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                        && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                        && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
      var is_nav4 = (is_nav && (is_major == 4));
      var is_nav6 = (is_nav && (is_major == 5));
      var is_nav6up = (is_nav && (is_major >= 5));
      var is_ie      = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
</script>
<script language="JavaScript">
//tooltip Position
var offsetX = 0;
var offsetY = 5;
var opacity = 100;
var toolTipSTYLE;
 
function initToolTips(){
   if(document.getElementById){
               toolTipSTYLE = document.getElementById("toolTipLayer").style;
   }
   if(is_ie || is_nav6up)
   {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
      document.onmousemove = moveToMousePos;
   }
}
function moveToMousePos(e)
{
   if(!is_ie){
      x = e.pageX;
      y = e.pageY;
   }else{
      x = event.x + document.body.scrollLeft;
      y = event.y + document.body.scrollTop;
   }
 
   toolTipSTYLE.left = x + offsetX+'px';
   toolTipSTYLE.top = y + offsetY+'px';
   return true;
}
 

function toolTip(msg, fg, bg)
{
   if(toolTip.arguments.length < 1) // if no arguments are passed then hide the tootip
   {
      if(is_nav4)
            toolTipSTYLE.visibility = "hidden";
      else
            toolTipSTYLE.display = "none";
   }
   else // show
   {
      if(!fg) fg = "#777777";
      if(!bg) bg = "#ffffe5";
      var content = '<table border="0" cellspacing="0" cellpadding="0" class="toolTip"><tr><td bgcolor="' + fg + '">' +
                                                   '<table border="0" cellspacing="1" cellpadding="0"<tr><td bgcolor="' + bg + '">'+
                                                   '<font face="sans-serif" color="' + fg + '" size="-2">' + msg +
                                                   '</font></td></tr></table>'+
                                                   '</td></tr></table>';
   if(is_nav4)
      {
         toolTipSTYLE.document.write(content);
         toolTipSTYLE.document.close();
         toolTipSTYLE.visibility = "visible";
      }
 
      else if(is_ie || is_nav6up)
      {
         document.getElementById("toolTipLayer").innerHTML = content;
         toolTipSTYLE.display='block'
      }
      s = '<table width="100%" cellspacing="2" cellpadding="0" border="0">';
      s += '<tr><td><img src="http://upload.wikimedia.org/wikipedia/meta/2/2a/
            Nohat-logo-nowords-bgwhite-200px.jpg" border="0"/> </td>
            <td valign="top">WikiPedia</td></tr>';
      s += '<tr><td colspan="2" class="Text">
      <hr/>this is a test for simple tooltip.
      <br/>You can add text and images to the tooltip</td></tr>';
      s += '</table>'
   }
  
  
}
 
function show()
{
  
      toolTip(s)
}
 
</script>
  
     
</head>
<body onload="initToolTips();">
      <form id="form1" runat="server">
      <div>
      <span onMouseOver="toolTip('simple Tooltip Text here')" onMouseOut="toolTip()" class="Text">Simple Tooltip</span>
<br/><br/>
<span onMouseOver="toolTip('Tooltip with colors set', '#FFFF00', 'orange')";   onMouseOut="toolTip()";   class="Text">Tooltip with Font Colors Set</span>
<br/><br/>
      <span onMouseOver="show()" onMouseOut="toolTip()" class="Text">Tooltip with Images and Text</span>
<br/><br/>
<span class="Text"> The Microsoft .NET Framework is a software component that can be added to or is included with Microsoft Windows operating system. It provides a large body of pre-coded solutions to common program requirements, and manages the execution of programs written specifically for the framework. The .NET Framework is a key Microsoft offering, and is intended to be used by most new applications created for the Windows platform.</span>
 
     
 
      </div>
      </form>
</body>
</html>
 

Thanks for yor time
Manish

 
ManishTech
GeneralRe: The way i used your codememberKumar Sundaram27 Sep '07 - 15:28 
Hi Manish,
gone thru the code you have posted earlier. There are some problems like,
you have mis placed some lines of code in another function
 
<pre><code>
you have mis placed the following 4 lines elsewhere inside the toolTip function
 
      s = '<table width="100%" cellspacing="2" cellpadding="0" border="0">';
      s += '<tr><td><img src="http://upload.wikimedia.org/wikipedia/meta/2/2a/Nohat-logo-nowords-bgwhite-200px.jpg" border="0"/> </td><td valign="top">WikiPedia</td></tr>';
      s += '<tr><td colspan="2" class="Text"><hr/>this is a test for simple tooltip.<br/>You can add text and images to the tooltip</td></tr>';
      s += '</table>'
 
these lines should be inside the show() function.
 
and have forgotten to add the div for showing the tootip.
You have forgotten to add this toolTipLayer div layer
<div id="toolTipLayer" style="position:absolute; visibility: hidden;leftBlush | :O ;rightBlush | :O "></div>
 
the following is the code i've changed
 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
      <title>Untitled Page</title>
      <style type="text/css">
.Text{
            font-family: Verdana, Arial, Sans-serif, 'Times New Roman';
            font-size: 8pt;
            font-weight: normal;
            font-style: normal;
            color: #333333;
            text-decoration: none;
}
 
.toolTip {
            font-family: Verdana, Arial, Sans-serif, 'Times New Roman';
            font-size: 8pt;
            filter:alpha(opacity=80);
            -moz-opacity: 0.8;
            opacity: 0.8;
            /* comment the above 3 line if you don't want transparency*/
}
 
</style>
 
<script language="javascript">
      var agt=navigator.userAgent.toLowerCase();
      var is_major = parseInt(navigator.appVersion);
      var is_minor = parseFloat(navigator.appVersion);
 
      var is_nav   = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                        && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                        && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
      var is_nav4 = (is_nav && (is_major == 4));
      var is_nav6 = (is_nav && (is_major == 5));
      var is_nav6up = (is_nav && (is_major >= 5));
      var is_ie      = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
</script>
<script language="JavaScript">
//tooltip Position
var offsetX = 0;
var offsetY = 5;
var opacity = 100;
var toolTipSTYLE;
 
function initToolTips(){
   if(document.getElementById){
               toolTipSTYLE = document.getElementById("toolTipLayer").style;
   }
   if(is_ie || is_nav6up)
   {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
      document.onmousemove = moveToMousePos;
   }
}
function moveToMousePos(e)
{
   if(!is_ie){
      x = e.pageX;
      y = e.pageY;
   }else{
      x = event.x + document.body.scrollLeft;
      y = event.y + document.body.scrollTop;
   }
 
   toolTipSTYLE.left = x + offsetX+'px';
   toolTipSTYLE.top = y + offsetY+'px';
   return true;
}
 

function toolTip(msg, fg, bg)
{
   if(toolTip.arguments.length < 1) // if no arguments are passed then hide the tootip
   {
      if(is_nav4)
            toolTipSTYLE.visibility = "hidden";
      else
            toolTipSTYLE.display = "none";
   }
   else // show
   {
      if(!fg) fg = "#777777";
      if(!bg) bg = "#ffffe5";
      var content = '<table border="0" cellspacing="0" cellpadding="0" class="toolTip"><tr><td bgcolor="' + fg + '">' +
                                                   '<table border="0" cellspacing="1" cellpadding="0"<tr><td bgcolor="' + bg + '">'+
                                                   '<font face="sans-serif" color="' + fg + '" size="-2">' + msg +
                                                   '</font></td></tr></table>'+
                                                   '</td></tr></table>';
   if(is_nav4)
      {
         toolTipSTYLE.document.write(content);
         toolTipSTYLE.document.close();
         toolTipSTYLE.visibility = "visible";
      }
 
      else if(is_ie || is_nav6up)
      {
         document.getElementById("toolTipLayer").innerHTML = content;
         toolTipSTYLE.display='block'
      }
   }
 

}
 
function show()
{
      /* you have mis placed the following 4 lines elsewhere inside the toolTip function */
      s = '<table width="100%" cellspacing="2" cellpadding="0" border="0">';
      s += '<tr><td><img src="http://upload.wikimedia.org/wikipedia/meta/2/2a/Nohat-logo-nowords-bgwhite-200px.jpg" border="0"/> </td><td valign="top">WikiPedia</td></tr>';
      s += '<tr><td colspan="2" class="Text"><hr/>this is a test for simple tooltip.<br/>You can add text and images to the tooltip</td></tr>';
      s += '</table>'
 
      toolTip(s)
}
 
</script>
 

</head>
<body onload="initToolTips();">
 
<!-- You have forgotten to add this toolTipLayer div layer -->
<div id="toolTipLayer" style="position:absolute; visibility: hidden;leftBlush | :O ;rightBlush | :O "></div>
<!-- You have forgotten to add this toolTipLayer div layer -->
 
      <form id="form1" runat="server">
      <div>
      <span onMouseOver="toolTip('simple Tooltip Text here')" onMouseOut="toolTip()" class="Text">Simple Tooltip</span>
<br/><br/>
<span onMouseOver="toolTip('Tooltip with colors set', '#FFFF00', 'orange')";   onMouseOut="toolTip()";   class="Text">Tooltip with Font Colors Set</span>
<br/><br/>
      <span onMouseOver="show()" onMouseOut="toolTip()" class="Text">Tooltip with Images and Text</span>
<br/><br/>
<span class="Text"> The Microsoft .NET Framework is a software component that can be added to or is included with Microsoft Windows operating system. It provides a large body of pre-coded solutions to common program requirements, and manages the execution of programs written specifically for the framework. The .NET Framework is a key Microsoft offering, and is intended to be used by most new applications created for the Windows platform.</span>
 

 
      </div>
      </form>
</body>
</html></code>
</pre>
GeneralRe: The way i used your codememberSurjit Singh Dadhwal4 Sep '08 - 13:01 
Hi,
This post is good, but the changes you have made in your feedback should go in the project been given as download option in Code Project; as these four lines are inside the ToolTip function only.
 
Thanks
Surjit Dadhwal
GeneralWorking NowmemberKumar Sundaram27 Sep '07 - 15:36 
Please try with the code i've modified and posted in my message.
 
If there are problems download the source again and modify to add into your asp page.
let me know if any.
 
Regards,
Kumar S
QuestionScript Error When MouseOver Occurs Before Page Fully LoadsmemberDianal26 Sep '07 - 9:40 
Hello,
 
This is a wonderful script. I've been able to apply it to a web page with multiple model pictures on it, and when hovering over each picture, the tooltip pops up great.
 
During testing however, I just happened to reload a page and quickly move the mouse over the spot where an image would appear after the page fully loads. I received a script error: 'toolTipSTYLE' is null or not an object.
 
I'm using IE6, and I have it set to enable script debugging, so I see every script error when most users would not. When I get the error, it asks if I want to debug. Clicking NO allows the page to fully load, and after that I don't get the error anymore.
 
If I click YES to debug, the error is caused in the toolTip function:
 

else if(is_ie || is_nav6up)
{
document.getElementById("toolTipLayer").innerHTML = content;
toolTipSTYLE.display='block'
}

 
Is there something you can suggest that would prevent this from happening? While most IE users don't have script debugging enabled and wouldn't see the error, I don't feel comfortable uploading a page with the possibility of producing the error.
 

 
Thanks for your time.
Diana
AnswerRe: Script Error When MouseOver Occurs Before Page Fully LoadsmemberKumar Sundaram26 Sep '07 - 15:15 
As you have mentioned, before the page is fully loaded, trying the mouse over triggers the error.
This can be fixed and will give an update on this.
 

Thanks for informing.
 
Regards,
Kumar S
GeneralRe: Script Error When MouseOver Occurs Before Page Fully LoadsmemberDianal10 Oct '07 - 9:12 
Hello Kumar,
 
Have you had the opportunity to look into the mouseover error? I'm not sure what to look for as far as the update goes.
 
Thanks for your help,
Diana
QuestionProblem is not solvedmemberManishTech24 Sep '07 - 19:45 
Hi,
Thanks for your reply . I used your suggestion implement the code in exact way as you told me.I called the function in such a way.
 
<span onMouseOver="toolTip('simple Tooltip Text here')" onMouseOut="toolTip()" class="Text">Simple Tooltip</span>
<br/><br/>
<span onMouseOver="toolTip('Tooltip with colors set', '#FFFF00', 'orange')";   onMouseOut="toolTip()";   class="Text">Tooltip with Font Colors Set</span>
<br/><br/>
      <span onMouseOver="show()" onMouseOut="toolTip()" class="Text">Tooltip with Images and Text</span>
<br/><br/>
<span class="Text"> The Microsoft .NET Framework is a software component that can be added to or is included with Microsoft Windows operating system. It provides a large body of pre-coded solutions to common program requirements, and manages the execution of programs written specifically for the framework. The .NET Framework is a key Microsoft offering, and is intended to be used by most new applications created for the Windows platform.</span>
 
I paste all the javascript code in side the head tag as you say.I used javascript tag in such a way
<script="Javascript" defer="false">
.But I am unable to execute the code.
Please help me.
I used VS.Net 2005.
 

 
ManishTech
AnswerRe: Problem is not solvedmemberKumar Sundaram26 Sep '07 - 15:21 
Can you please mail the code you are working on? so that i can look into that what is going wrong.
 
Meanwhile try this,
I've asked you to remove the defer="false" in the script tag.
Next try with the document type you are using. Try changing the doctype to different.
 
Try with a simple page and confirm everything working, then move to the actual working page.
 
cheers. expecting your feedback.
 
Regards,
Kumar S
QuestionI am Unable to implement the code Please HelpmemberManishTech21 Sep '07 - 20:14 
Hi,
Thanks of this wondefull tooltip demo.But unfortunetly I am unable to use the code.Will you help me. I used the code in such a way.
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.Text{
font-family: Verdana, Arial, Sans-serif, 'Times New Roman';
font-size: 8pt;
font-weight: normal;
font-style: normal;
color: #333333;
text-decoration: none;
}
 
.toolTip {
font-family: Verdana, Arial, Sans-serif, 'Times New Roman';
font-size: 8pt;
filter:alpha(opacity=80);
-moz-opacity: 0.8;
opacity: 0.8;
/* comment the above 3 line if you don't want transparency*/
}
 
</style>



</head>
<body önload="initToolTips();">
<form id="form1" runat="server">
Simple Tooltip



Tooltip with Font Colors Set



Tooltip with Images and Text



The Microsoft .NET Framework is a software component that can be added to or is included with Microsoft Windows operating system. It provides a large body of pre-coded solutions to common program requirements, and manages the execution of programs written specifically for the framework. The .NET Framework is a key Microsoft offering, and is intended to be used by most new applications created for the Windows platform.
 
<script language="javascript" defer="defer">
browser detection
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
 
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
</script>
<script language="JavaScript">
//tooltip Position
var offsetX = 0;
var offsetY = 5;
var opacity = 100;
var toolTipSTYLE;
 
function initToolTips(){
if(document.getElementById){
toolTipSTYLE = document.getElementById("toolTipLayer").style;
}
if(is_ie || is_nav6up)
{
toolTipSTYLE.visibility = "visible";
toolTipSTYLE.display = "none";
document.onmousemove = moveToMousePos;
}
}
function moveToMousePos(e)
{
if(!is_ie){
x = e.pageX;
y = e.pageY;
}else{
x = event.x + document.body.scrollLeft;
y = event.y + document.body.scrollTop;
}
 
toolTipSTYLE.left = x + offsetX+'px';
toolTipSTYLE.top = y + offsetY+'px';
return true;
}
 

function toolTip(msg, fg, bg)
{
if(toolTip.arguments.length < 1) // if no arguments are passed then hide the tootip
{
if(is_nav4)
toolTipSTYLE.visibility = "hidden";
else
toolTipSTYLE.display = "none";
}
else // show
{
if(!fg) fg = "#777777";
if(!bg) bg = "#ffffe5";
var content = '
' +
'
'+
'' + msg +
'
'+
'
';
if(is_nav4)
{
toolTipSTYLE.document.write(content);
toolTipSTYLE.document.close();
toolTipSTYLE.visibility = "visible";
}
 
else if(is_ie || is_nav6up)
{
document.getElementById("toolTipLayer").innerHTML = content;
toolTipSTYLE.display='block'
}
s = '';
s += '';
s += '';
s += '
<img src="http://upload.wikimedia.org/wikipedia/meta/2/2a/
Nohat-logo-nowords-bgwhite-200px.jpg" border="0"/>
WikiPedia


this is a test for simple tooltip.

You can add text and images to the tooltip
'
}


}
 
function show()
{

toolTip(s)
}
 
</script>

 
</form>
</body>
</html>
 
Confused | :confused: Please Help
 
Thanks & Regards
Manish

 
ManishTech
AnswerRe: I am Unable to implement the code Please HelpmemberKumar Sundaram21 Sep '07 - 22:23 
The problem is you have not added the code to call the tootip,
You have added only text as like below,
Simple Tooltip
Tooltip with Font Colors Set
Tooltip with Images and Text
 
Actually you have to call like ths
<span onMouseOver="toolTip('simple Tooltip Text here')" onMouseOut="toolTip()" class="Text">Simple Tooltip</span>
<br/><br/>
<span onMouseOver="toolTip('Tooltip with colors set', '#FFFF00', 'orange')";   onMouseOut="toolTip()";   class="Text">Tooltip with Font Colors Set</span>
<br/><br/>
<span onMouseOver="show()" onMouseOut="toolTip()" class="Text">Tooltip with Images and Text</span>
<br/><br/>
 
Also move all the javascript into the top of the page. specifically into the head section of the page.
 
then add the lines inside the body where ever you like.
 
Also I there are some errors in loading the javascript try removing the defer="false" in the < script tag.
 
Let me know It works.

 
Kumar S
GeneralCursor-Hand additionmemberkdamalie17 Sep '07 - 12:16 
I modified the html a little so it displays the cursor as hand
 
style="cursor:hand;cursor:pointer"
 
Tooltip with Images and Text
 

Kdamalie

GeneralRe: Cursor-Hand additionmemberKumar Sundaram18 Sep '07 - 16:21 
When you want to add a hand type cursor always use cursor:hand instead of cursor:pointer. because it will not work in all browsers.
 
The reason is IE supports the keyword hand and mozilla, netscape, firefox do not.
If You want to use cursor: hand; to work on all the browsers, simply use
cursor: pointer
 
Kumar S

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 17 Sep 2007
Article Copyright 2007 by Kumar Sundaram
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid