I have used jQuery library to find out height of a
Below is my
div element with attributes :
<DIV id="myDiv" style="height:auto; width:78;overflow:hidden"> Simple Test</DIV>
Below is my jQuery code to get height of
var result = $("#myDiv").css('height'); alert(result);
After executing above statement I am getting result as “auto”. Actually this is I am not expecting, instead of that I want the result in px dimension.
.height() like this:
var result = $("#myDiv").height();
You can test it here, play with the padding/margins/content to see how it changes around.
Although they vary slightly as to how they retrieve a height value, i.e some would calculate the whole element including padding, margin, scrollbar, etc and others would just calculate the element in its raw form.
You can try these ones:
var myDiv = document.getElementById("myDiv"); myDiv.clientHeight; myDiv.scrollHeight; myDiv.offsetHeight;
or in jquery:
$("#myDiv").height(); $("#myDiv").innerHeight(); $("#myDiv").outerHeight();
var result = $("#myDiv").height(); alert(result);
This will give you the unit-less computed height in pixels. “px” will be stripped from the result. I.e. if the height is 400px, the result will be 400, but the result will be in pixels.
var result = document.getElementById("myDiv").offsetHeight;