View Full Version : Why offsetXXX properties are all zero ?

06-10-2004, 11:47 PM

I've done control in asp.net/javascript and it works on some pages of mine and as it often happens doesn't work on customer's pages ;).
All pages are run in IE 6.0.
After I run debugger I've found out that on my page offsetLeft/Top clientHeight properties have some non-zero values.
I have <span id="listCLient" style="width:200px;">..</span> and on my test page elListClient.clientHeight = 200, but on customer's app's page it is 0x0 ?
Same with other offsetXXX properties etc.
But elListClient.style.height bears correct value.
I use those properties everywhere.

I think it is some settings somewhere ? or CSS styles ?
Can anyone help ?

Thanks a lot


06-11-2004, 09:32 AM
clientHeight/Width are property of body, not of an object nested in body. Thus in your example I think elListClient.clientHeight is an incorrect syntax.

If you want to retreive the objects size use


06-11-2004, 10:42 AM
This is a dropdownlist control.
I have 4 elements: textbox (this.elInput), button (this.elButton),
div (elDropDown) that's hidden, when I press a button it is visible and surronding span object (this.elMain).
I set size of the textbox based on size of surrounding elMain minus size of a button and then position dropdown beneath textbox and button (they are on one line)
So I have this code:
// set width of the text box
this.elInput.style.width = this.elMain.clientWidth - this.elButton.offsetWidth;
// position the divDropDown
this.elDropDown.style.top = this.elMain.offsetTop + this.elInput.offsetHeight;
this.elDropDown.style.left = this.elMain.offsetLeft;
this.elDropDown.style.width = this.elMain.clientWidth;

Syntax is correct becuase it works on my test page and IE 6.0.
It doesn't work on the production page of my customer - textbox doesn't show only a button. So I asked him to go into a debugger and it appeared that this.elMain.clientWidth = 0,this.elMain.offsetTop = 0, this.elMain.offsetLeft = 0. However control is not at the top of the page and I have style="width:250px;" on span (this.elMain) so clientHeight has not to be a 0. But this.elMain.style.width is "250px".


06-11-2004, 10:53 AM
It's better that you post the whole code or post a link to visualize the whole thing.

06-11-2004, 12:06 PM

06-11-2004, 12:34 PM
I found the reason why properties offsetTop/Left/Width/Height are al zero. That happens when I put my control inside of the table's cell. Only I put it outside of the table all properties have non zero values.
I'll try to give a link here.


06-12-2004, 01:36 PM
I've found my bug now. I was registering my script that defines my object near my object's html tags. So if I move script to the end of page all is OK.
Maybe when script was in the table browser didn't finished creating a table and other it's objects and that time I tried to measure them with offsetWidth etc.

Roy Sinclair
06-14-2004, 05:52 PM
Maybe when script was in the table browser didn't finished creating a table and other it's objects and that time I tried to measure them with offsetWidth etc.

That would be true, until the browser processes the </table> tag it may end up re-arranging the table because some cell's content requires a larger than specified amount of space so it doesn't "fill-in" the position information until it's sure what it'll contain.

05-30-2010, 10:41 AM
Thanks for your posts on the problem's source. This was a really great help as I had the same problem with script before layout table's end in IE6.