Tuesday, June 4, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  67] [ 2]  / answers: 1 / hits: 22376  / 12 Years ago, sun, november 18, 2012, 12:00:00

I have a problem getting the height of a (the one in the code below, with class=post_div). And I want to return with a document.write whitin the HTML body - maybe later using it as height for other elements, that I want to be equal. I have tried every possible code for getting the height of such an element, but every time it returns 'undefined'. I have also tried setting height=auto for the DIV. I am almost sure my problem not has to do with the way I get the height, but have no other idea for what else it could be! Therefore I have choosen to bother you with the full structure of my coding. The JavaScript is placed in a separate document containing only the following statement:



var result=document.getElementById('postHeight').offsetHeight;


My HTML document looks like this



<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<head>
<title>...</title>
<link rel=stylesheet type=text/css media=all href=C:UsersLasseDesktophg2hg2.css />
<script src=C:UsersLasseDesktophg2hg2.js></script>
</head>
<body>

<script>document.write(result)</script>

<div id=postHeight class=post_div>
...
</div>


</body>
</html>


Hope you can help! Thanks!


More From » html

 Answers
37

There is no element with the ID postHeight. Perhaps you meant



var result=document.getElementById('content').offsetHeight;


Additionally, this calculation must be done after the element you are calculating has been loaded (so either by putting the <script> after the element, or deferring execution with onload or similar).


[#81928] Friday, November 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
samir

Total Points: 145
Total Questions: 90
Total Answers: 89

Location: Tokelau
Member since Sun, May 7, 2023
1 Year ago
;