How to get the height of an element in ie?

M

Me

The following code, I got 0 in firefox, but 600 in ie.
How to get the corrent height of element "header" ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
</head>
<body>
<div id="header">
</div>
<div id="container" style="width: 98%">
<DIV id=map style="POSITION: relative; HEIGHT: 600px; BACKGROUND-
COLOR: #e5e3df"></DIV>
</DIV>
</body>
<script type="text/javascript">
alert(document.getElementById("header").offsetHeight);
</script>
</html>
 
D

David Mark

The following code, I got 0 in firefox, but 600 in ie.
How to get the corrent height of element "header" ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www..w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Why XHTML transitional for a new document?
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />

You clearly don't plan to serve this as XHTML.
  </head>
  <body>
    <div id="header">
    </div>
    <div id="container" style="width: 98%">
      <DIV id=map style="POSITION: relative; HEIGHT: 600px; BACKGROUND-
COLOR: #e5e3df"></DIV>
    </DIV>
  </body>
  <script type="text/javascript">
    alert(document.getElementById("header").offsetHeight);
  </script>

This is invalid markup. Scripts must reside in the body or head.

The offsetHeight property of elements is not guaranteed to be
meaningful until after the document has completed parsing. Wrap code
that measures element dimensions in a load event listener.
 
M

Me

Thanks for your reply. I copied parts of the code from other sites'
source code
After changing to the following code, I got the same value :(

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function dotest(){
alert(document.getElementById("header").offsetHeight);
}
</script>
</head>
<body onload="dotest()">
<div id="header">
</div>
<div id="container" style="width: 98%">
<DIV id=map style="POSITION: relative; HEIGHT: 600px; BACKGROUND-
COLOR: #e5e3df"></DIV>
</DIV>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top