HTML: Calculating the height of a DIV-Container

Today i had to calculate the height of a DIV-Container in Javascript:

1. Select the DIV-Container to calculate carefully, if you have a div container only with sub div containers in it and no other container, select the sub containers for calculation, if you have to know the outer div containers height, sum up both sub containers height.

2. If you haven’t yet, assign IDs to the div containers

3. use this code to get the height of the div-container:

var divelement = document.getElementById("divID");
calculatedHeight = divelement.offsetHeight;

It is important to use “offsetHeight” and not “clientHeight” as the Internet Explorer (version 7) does not parse this correctly.

The code

var divelement = document.getElementById("divID");
calculatedHeight = divelement.clientHeight;

does not work in all circumstances.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>