Jump to content

help getting height of a div


meomike2000

Recommended Posts

i need to be able to get the height of a div....

 

i dont want to specify the height of the div due to the fact that as things get added to it the height will change...

 

the width is specifed....

 

i tried some thing like this,

 

var hheight = hiddendiv.style.height;

 

but it will only return the value that i pre set for the div.....

if i dont set a height it returns blank or undefined.....

 

any help would be great,

thanks in advance mike.......

Link to comment
Share on other sites

I notice you're using the word hidden in your js. If your element is indeed hidden the height will be simply 0.

 

<script type="text/javascript">
window.onload = function() {
var hiddendiv = document.getElementById('hiddendiv');
var height = hiddendiv.offsetHeight;
alert(height);
}
</script>
<div id="hiddendiv">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ullamcorper hendrerit est, in eleifend orci volutpat eget. Integer tellus risus, mattis sed venenatis nec, faucibus a ligula. Quisque in sem eget diam semper venenatis. Sed ut est neque, imperdiet iaculis augue. Nulla lacinia eros at felis pharetra sodales interdum dolor bibendum. Integer enim nulla, tristique et mollis eu, commodo et lectus. Vivamus tempus feugiat luctus. Curabitur interdum pharetra odio vitae fringilla. Vestibulum tortor odio, eleifend nec faucibus ac, fringilla sit amet enim. Nullam blandit urna non turpis aliquet aliquam. Donec dignissim rutrum facilisis. Etiam interdum, felis et tincidunt consectetur, dui lacus convallis elit, vitae blandit massa tellus ut ipsum. Curabitur ultrices interdum tristique. Nam orci dui, ornare eu imperdiet et, varius in dui. Quisque vel ante urna, ut convallis libero. Duis sit amet mauris at felis dignissim faucibus sed id orci. Donec lorem diam, dignissim sed dignissim in, porta sed diam.
</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.