[ IE ] offsetWidth returns 0

I developed a Grid that sometimes resides within a table. The Grid is created with the DOM and inserted in its parent element. Problem is that IE returns offsetWidth/offsetHeight 0 when you check its offsetWidth.

For example, the following code will return 0, while Firefox returns its correct width.


<table border="1">
<tr>
	<td id="myCell">
		Some text goes here...
		<script type="text/javascript">
			alert(document.getElementById("myCell").offsetWidth);
		</script>
	</td>
</tr>
</table>

I read somewhere that IE renders the table once it has read the entire table, so my guess is that offsetWidth returns 0 because the table is not yet rendered and its not part of the DOM?

Anyway, if anybody would know how to avoid this it would be great. This problem does not appear inside a DIV, but in this very case it must be inside a table…

A timer does the trick, but that is a cheap crappy solution I would like to avoid.

Yes, try checking it after the page has finished loading.

Yeah, i guess that is the only way to solve this. Sucks though, since some pages has 2 grids and it kind of “flickers” if you add them onload… Anyway… thanks

You’re welcome :slight_smile:

You could add them to a div that’s positioned off the left side of the screen so it isn’t visible and then remove the absolute positioning from it.

Hm, I simply ended up using a timer to instanciate each Grid. Crap solution for a crap browser. Works like a charm in all other browsers.