offsetParentoffsetParent*
*



Contents  *



Index  *Topic Contents
*Previous Topic: offsetLeft
*Next Topic: offsetTop

offsetParent

Description

Returns a reference to the container element that defines the top and left offsets for the object.

Syntax

object.offsetParent

Remarks

The offsetLeft and offsetTop property values are relative to the element specified by the offsetParent property for the element. Most of the time the property returns BODY. For example, in the following document, even though the TD element 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.MyID;
    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=MyID>This is a small table
</TABLE>
</BODY>
</HTML>

This property has read-only permission.

Applies To

A, ACRONYM, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, COMMENT, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, H1, H2, H3, H4, H5, H6, HR, I, IFRAME, IMG, INPUT, INS, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.