Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-11-2002, 01:25 PM   PM User | #1
DanLap
New Coder

 
Join Date: Jul 2002
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
DanLap is an unknown quantity at this point
How to establish the width of a span

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
__________________
Daniel

Last edited by DanLap; 07-11-2002 at 01:28 PM..
DanLap is offline   Reply With Quote
Old 07-11-2002, 03:45 PM   PM User | #2
JohnKrutsch
Regular Coder

 
Join Date: Jun 2002
Location: The Planet Earth Code Poet: True
Posts: 282
Thanks: 0
Thanked 1 Time in 1 Post
JohnKrutsch is an unknown quantity at this point
Something like this ought to do it:

Code:
<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>
JohnKrutsch is offline   Reply With Quote
Old 07-11-2002, 03:50 PM   PM User | #3
DanLap
New Coder

 
Join Date: Jul 2002
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
DanLap is an unknown quantity at this point
Works great thanks
__________________
Daniel
DanLap is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:08 AM.


Advertisement
Log in to turn off these ads.