offsetHeight property

all
alt
ch
dir
id
min
rel
top
url
URL
urn
Expand Minimize
This topic has not yet been rated - Rate this topic

Retrieves the height of the object relative to the layout or coordinate parent, as specified by the offsetParent property.

Syntax

JavaScript

p = object.offsetHeight

Property values

Type: Integer

the height, in pixels.

Remarks

You can determine the location, width, and height of an object by using a combination of the offsetLeft, offsetTop, offsetHeight, and offsetWidth properties. These numeric properties specify the physical coordinates and dimensions of the object relative to the object's offset parent.

For more information about how to access the dimension and location of elements on the page through the Dynamic HTML (DHTML) Document Object Model (DOM), see Measuring Element Dimension and Location with CSSOM in Internet Explorer 9.

Examples

This example adjusts the size of a clock's readout to fit the current width and height of the document body.


<html>

<head>
<title>A Simple Clock</title>
<script language="JavaScript">
function startClock()
{
    window.setInterval("Clock_Tick()", 1000);
    Clock_Tick();
}

var iRatio = 4;
function Clock_Tick()
{
    var dToday = Date();
    var sTime = dToday.substring(11,19);
    var iDocHeight = document.body.offsetHeight;
    var iDocWidth = document.body.offsetWidth;

    if ((iDocHeight*iRatio)>iDocWidth)
        iDocHeight = iDocWidth / iRatio;
    document.all.MyTime.innerText = sTime;
    document.all.MyTime.style.fontSize = iDocHeight;
}
</script>
</head>

<body onload="startClock()">

<p id="MyTime">&nbsp;</p>

</body>

</html>


This example uses the offsetHeight property and the clientHeight property to show different ways of measuring the object size.


<div id="oDiv" style="overflow: scroll; width: 200; height: 100">
	. . . </div>
<button onclick="console.log(oDiv.clientHeight)">client height</button>
<button onclick="console.log(oDiv.offsetHeight)">offset height</button>

See also

a
abbr
address
area
article
aside
b
bdo
blockQuote
body
br
button
caption
cite
code
col
colGroup
custom
dd
del
div
dl
dt
em
embed
fieldSet
figcaption
figure
footer
form
head
header
hgroup
hn
hr
html
i
iframe
img
input type=button
input type=checkbox
input type=file
input type=hidden
input type=image
input type=password
input type=radio
input type=reset
input type=submit
input type=text
ins
kbd
label
legend
li
map
mark
nav
object
ol
optGroup
option
p
pre
q
rt
ruby
s
samp
section
select
small
span
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
tr
u
ul
var

 

 

Build date: 11/28/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.