Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Firefox offsetheight problem 1

Status
Not open for further replies.

guitardave78

Programmer
Sep 5, 2001
1,294
GB
Hi all.
I am dynamically adding text to a div using the innerHTML

I then need to get the height of the div.
In IE i can use offsetheight but in firefox this does not seem to work

It is fine if i manually add text to the div

Anyone able to help/

}...the bane of my life!
 
Works fine for me......

This alerts 192 in IE and 202 in firefox:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

window.onload = function () {
   document.getElementById("theDiv").innerHTML = "asdlkfj sadlfk jasdflkj asdflk jsadflkjaskhzxc,mn zxcv,mn xzvc,mn zxcv,m nzxvoiqwueroiu qweroiu qweroiu qweroiu qweroiu qwer";
   alert(document.getElementById("theDiv").offsetHeight);
};

</script>
<style type="text/css">
div#theDiv {
   width:100px;
   border:1px solid black;
}
</style>
</head>
<body>
<div id="theDiv">
</div>
</body>
</html>

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
anyone got a hose pipe?

Code:
<html>
<div id="mydiv">my div</div>
</html>
<script>
var divHeight=0;			
d = document.getElementById('mydiv');

if(d.offsetHeight){		
  divHeight=d.offsetHeight;			
}
else if(d.style.pixelHeight){				divHeight=d.style.pixelHeight;			
}

alert("Div Height = " + divHeight);
</script>

That is direct from the link I gave you except for obviously adding the DIV!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
lol - well done kaht, have a star!, I got 19 in IE and 20 in FF for my example!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
mm I think it is that firefox is slower to add the content than IE, so have added a time delay to allow ff time to catch up on large inputs.

}...the bane of my life!
 
Hmmm... that's possible, strange problem. I guess the code works now?

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top