Hi,
I have an onmouseover script that displays a div with some comment. There
are several links getting this onmouseover functionality, all with their own
comment text. Now I want the div to have a max width, but if the natural
width is smaller than the max width, it should get the natural width.
commentObj is the div and commentObj.offsetWidth returns the natural width,
as long as we didn't set it to anything else (it seems). As soon as we set
commentObj.style.width to something, there is no turning back and all
comments are equally wide, and the div doesn't return to a natural width
anymore.
For reference, I copied the function that is executed onmouseover below. The
actual positioning happens in a onmousemove action, but that is not relevant
here.
So, basically, the question is: is there a way to get the natural width of
the div or of the text in it? I expected that the natural width of the div
would reset when I put some new text in, but it doesn't, so I need another
function to get the natural width of the text.
Thanks, best regards,
-Hendri Adriaens.
function showComment(text,obj,move,dark,commentWidth)
{
popUp=true;
moveComment=move;
referrerObj=obj;
referrerObj.onmouseout=hideComment;
commentObj.innerHTML=text;
if (commentWidth!=0)
{
if (commentObj.offsetWidth>commentWidth)
{
commentObj.style.width=commentWidth+"px";
}
}
if (dark)
{
commentObj.style.background="#CCAA55";
}
else
{
commentObj.style.background="#F5EBCE";
}
}