Retrieves the calculated top position of the object relative to the layout or coordinate parent, as specified by the offsetParent property.
Syntax
HTML
N/A
Scripting
[ iCoord = ] object.offsetTop
Possible Values
iCoord
Integer that
receives the top position, in pixels.
The property is read-only.
The property has no default value.
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 objects on the page through the Dynamic HTML (DHTML)Â Document Object Model (DOM), see>Measuring Element Dimension and Location.
Example
This example uses the offsetTop property to determine whether an object is in the user's view.
<HTML>
<HEAD>
<SCRIPT>
function isinView(oObject)
{
var oParent = oObject.offsetParent;
var iOffsetTop = oObject.offsetTop;
var iClientHeight = oParent.clientHeight;
if (iOffsetTop > iClientHeight) {
alert("Special Text not in view. Expand Window to put Text in View.");
}
else{
alert("Special Text in View!");
}
}
</SCRIPT>
</HEAD>
<BODY onload="window.resizeTo(430,250)" onclick="isinView(oID_1)" SCROLL=NO>
<DIV STYLE="position:absolute;left:20px">Click anywhere in window to see if special text is in
view.</DIV>
<DIV id="oID_1" STYLE="position:absolute; left:50px;top:300px;width:280px;color:lightGreen;
font-size:large;font-weight:bold;background-color:hotPink;font-family:Arial">
Here's some special text
</DIV>
</BODY>
</HTML>
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.
Standards Information
There is no public standard that applies to this property.