Forum Moderators: open
This is known as 'alt text' which you include by using alt="your text here" in your image tag, e.g.
<img src="image.gif" alt="my alt text">
[w3.org...]
Remember, if the user has javascript disabled, your javascript tooltips will not function. The title attribute is probably the safest and most efficient way of doing this but your tips need to be short and sweet. ;)
var absStr = "Position:Absolute;Top:0;Left:0";
var yOff = 70; // use this to position the message in the vertical axis
var xOff = 20; // use this to position the message in the horizontal axis
function stayHome(){
iL = document.body.scrollLeft;
iV = document.body.scrollTop;
mX = event.screenX-xOff+iL;
mY = event.screenY-yOff+iV;
isFloat.style.left = mX;
isFloat.style.top = mY;
}
document.onmousemove = stayHome;
window.onscroll = stayHome;
function insertFloatIMG(){
styleStr = "<Style>.msgFloat {"+absStr+";Border-Style:Solid;Border-Width:1px;Background-Color:Yellow;Padding-Right:5px;Padding-Left:5px;Padding-Top:3px;Padding-Bottom:3px;Font-family:Tahoma;Font-Size:13pt;Line-Height:95%;}</Style>";
divStr = "<DIV class=msgFloat id=isFloat> Null </DIV>"
document.write(styleStr);
document.write(divStr);
}
function hideMessage(){
isFloat.style.visibility = 'hidden';
}
function showMessage(toolTip){
isFloat.style.visibility = 'visible'
isFloat.innerHTML = toolTip;
}
function initToolTip(){
insertFloatIMG();
hideMessage();
}
</Script>
</Head>
<BODY>
<center>
<p><img src='1/niagara.jpg' onmouseover="showMessage('Here is a custom tool tip')"; onmouseout="hideMessage()"></p>
<br>
<br>
<p><img src='1/medical.jpg' onmouseover="showMessage('And here is another custom tool tip <br> consisting of two lines')"; onmouseout="hideMessage()"></p>
<br>
<br>
<p><img src='1/niagara.jpg' onmouseover="showMessage('Here is a third tool tip')"; onmouseout="hideMessage()"></p>
<br>
<br>
<p><img src='1/medical.jpg' onmouseover="showMessage('And this is a fourth custom tool tip <br> consisting of two lines')"; onmouseout="hideMessage()"></p>
</center>
<Script> initToolTip() </Script>
</Body>
</HTML>
Neat solution, but for MSIE only (innerHTML, object.style).
Why didn't you make the stylesheet outside of the script? There's nothing in it that responds to the script, and the initial use of the variable could have just as easily been the variable value, itself.
For that matter, both the initToolTip() and the insertFloatIMG() functions seem unnecessary. You are creating a simple hidden DIV. Why use script to do that?
Just curious about your reasoning ...