...

View Full Version : How to establish the width of a span



DanLap
07-11-2002, 02:25 PM
I need to calculate the width of a span taking into account the font and size of it's contents. I want to use that width to position the span with a style:"position;absolute; left:xxx;" that will change depending on the with of the span.

Can anyone help me on this?

Thanks

JohnKrutsch
07-11-2002, 04:45 PM
Something like this ought to do it:



<span id="theSpan"><img src="image1.gif"></span>
<script>
if (document.layers){
w=document.layers["theSpan"].clip.width;
} else if (document.all && !document.getElementById){
w=document.all["theSpan"].offsetWidth;
} else if(document.getElementById){
w=document.getElementById("theSpan").offsetWidth;
}

alert(w);

</script>

DanLap
07-11-2002, 04:50 PM
Works great thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum