Current location: Hot Scripts Forums » General Web Coding » JavaScript » span's width and height are 0!


span's width and height are 0!

Reply
  #1 (permalink)  
Old 06-30-04, 04:50 AM
davidklonski davidklonski is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
span's width and height are 0!

Hello

I am displaying the following span on the screen:
Code:
<span id="myspan" style="position:absolute; width:0px; height:0px; left:0px; top:0px; display:none; z-index:1000;">
   <table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td>
          <img src="bullet.png" width="16" height="16" style="vertical-align:top">
        </td>
        <td nowrap width="100%" style="padding-left:2px">
           <a href="#" onclick="return false">View</a>
        </td>
      </tr>
      <tr>
        <td>
          <img src="bullet.png" width="16" height="16" style="vertical-align:top">
        </td>
        <td nowrap width="100%" style="padding-left:2px">
          <a href="test.html">Test</a>
        </td>
      </tr>
    </table>
</span>
I set the body's style attribute to: position:relative
The span will get displayed on the screen as a trigger for some event. (where its final left and top attributes will be calculated and assigned, and it will then become visible)

for debug purposes, I am running the following on the onload event of the body:
Code:
var menu = document.getElementById('myspan');	
var width = menu.offsetWidth;	
var height = menu.offsetHeight;
alert("width: " + width + "'nheight: " + height);
For some reason, the values I am getting are 0!
Can anyone tell me what is wroing with my code?

I know that I set the width and height attribute to 0px when the span was defined because I don't know in advance what the actual dimensions of the span will be.

thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stuck on imagejpeg whilst trying to upload BLOB to MySQL! zcosgrove PHP 5 06-30-10 12:03 PM
how to obtain the width & height of the client area davidklonski JavaScript 1 05-14-05 03:13 PM
getting the actual widht and height of a span davidklonski JavaScript 0 06-29-04 12:47 PM
BUG in window.open(): resizable vs width bakcom JavaScript 0 12-15-03 07:41 AM
Perl class deadbeat teacher need help Teppic Perl 6 12-03-03 09:49 PM


All times are GMT -5. The time now is 07:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.