Forum Moderators: open
It seems that the scrollHeight property returns the wrong height if the javascript code and the target element are inside a table.
I'm very curious if there is an explanation to this.
@Purple Martin: Thanks for the link. But it doesn't explain wht's happening in my example. And a change of the Doctype doesn't make any diference.
To make the post shorter I only post the HTML code between the body tags:
<div id="test_1">Test Element 1</div>
<table>
<tr>
<td>
<div id="test_2">Test Element 2</div>
<script type="text/javascript">
<!--
alert(document.all["test_1"].scrollHeight); // 19
alert(document.all["test_2"].scrollHeight); // 0!
alert(document.all["test_2"].innerHTML); // Test Element 2 (just to be sure if other properties exist)
//-->
</script>
</td>
</tr>
</table>
<script type="text/javascript">
<!--
alert(document.all["test_1"].scrollHeight); // 19
alert(document.all["test_2"].scrollHeight); // 19
//-->
</script>
The alerts report the following on IE5 - IE6:
19
0
Test Element 2
19
19
The second value (0) is the problem. I can't find any explanation why this is happening. Especially because the same Javascript called outside the table a few lines below works perfectly.