DHTML Object Properties DHTML Objects
Returns a reference to the container object that defines the top and left offsets for the object.
HTML |
N/A |
Script |
[ oElement = ] object.offsetParent |
oElement |
Container object. |
The property is read-only with no default value.
The offsetLeft and offsetTop property values are relative to the object specified by the offsetParent property for the object. Most of the time the property returns BODY.
In the following document, even though the TD object appears to the far right in the document, its position is ( 0,0 ) because its offset parent is TR, not the document body.
<html>
<head>
<title>Elements: Positions</title>
</head>
<script language="JScript">
function showPosition ( ) {
var el = document.all.oCell;
alert ( "The TD element is at ( " +
el.offsetLeft + "," + el.offsetTop + " ) \n" +
"The offset parent is " + el.offsetParent.tagName );
}
</script>
<body onload="showPosition ( )">
<p>This document contains a right-aligned table.
<table BORDER=1 ALIGN=right>
<tr><td id=oCell>This is a small table.
</table>
</body>
</html>
Measuring Element Dimension and Location, The Browser Screen