How to find div height in JavaScript

{0 Comments}

To get the height of div in JavaScript following is the powerful JavaScript function I found on Google which is giving the result. So you can get the height of the div by using following function.  

 Javascript |  copy code |? 
01
function GetHeight() {
02
    var oDiv = document.getElementById("MyDiv");
03
    var sOriginalOverflow = oDiv.style.overflow;
04
    var sOriginalHeight = oDiv.style.height;
05
    oDiv.style.overflow = "";
06
    oDiv.style.height = "";
07
    var height = oDiv.offsetHeight;
08
    oDiv.style.height = sOriginalHeight;
09
    oDiv.style.overflow = sOriginalOverflow;
10
    alert("Real height is " + height);
11
}
12

Now other way which you can use to get the height of the div is by wrapping inner content in a paragraph tag and the assign a id to it then use the following script to get the height of the div.

 Javascript |  copy code |? 
1
var innerHeight = document.getElementById('yourparagraphID').offsetHeight;
2
alert(yourparagraphID);
3

Leave a Comment

Your email address will not be published.