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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cross browser specify element height

Status
Not open for further replies.

Slimsteve

Technical User
Jun 10, 2003
67
GB
Hi,

I am trying to use javascript to specify the height of a page element on page load. The following seems to work in IE but not in FF or NS.

I appreciate that I am likely to have to detect the browser type and window size for the design I have been given, but I need to set some element heights for different resolutions.

Any comments or suggestions appreciated.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style>
#main {background-color:#00CC00; width:100%; }
</style>

<script  language="javascript" type="text/javascript"> 
<!--
function testsize()
{
var varTopContWidth = document.getElementById("main").offsetHeight;
main.style.height = '55px';
}
-->
</script>


</head>

<body onLoad="testsize()">
<div id="main">
main
</div>


</body>
</html>
 
Change this
>[tt]main.style.height = '55px';[/tt]
to this
[tt]document.getElementById("main").style.height = '55px';[/tt]
The shortcut is only for ie, whereas using getElementById() you will be more comfortable with all w3c-compliant user agents.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top