It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Assigning the height of a Div to variable

Assigning the height of a Div to variable

Postby raman19 on Thu Apr 03, 2008 7:42 pm

Hi Everyone. I need to be able to capture the height of a div. i am enclosing my code. this is a simplified version of what i want to do. i have tried debuggin this using firebug. It seems that the "height" in the statement boxInFunction.style.height shows as undefined. Any help will be greatly appreciated.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.box{
height:100px;
background-color:green;
}
</style>
</head>
<body>
<div id="mybox" class="box" onClick="checkHeight('mybox');">
<h1> This is my box</h1>
</div>
<script type="text/javascript">
function checkHeight(boxname)
{
var boxInFunction =document.getElementById(boxname);
var boxHeight = boxInFunction.style.height;
alert(boxHeight);
}
</script>
</body>
</html>
raman19
 
Posts: 0
Joined: Thu Apr 03, 2008 7:38 pm

Postby rangana on Fri Apr 04, 2008 2:43 am

It should be ;)
Code: Select all
var boxHeight = boxInFunction.offsetHeight;


For further Reading ;)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 3 guests