Click to return to the DHTML, HTML     
offsetLeft Property     offsetTop Property     DHTML Properties    
Web Workshop  |  DHTML, HTML & CSS

offsetParent Property


Retrieves a reference to the container object that defines the offsetTop and offsetLeft properties of the object.

Syntax

HTMLN/A
Scripting[ oElement = ] object.offsetParent

Possible Values

oElementObject that specifies the container object.

The property is read-only with no default value.

Remarks

Most of the time the offsetParent property returns the BODY object.

Note In Microsoft® Internet Explorer 5, the offsetParent property returns the TABLE object for the TD object; in Internet Explorer 4.0 it returns the TR object. You can use the parentElement property to retrieve the immediate container of the table cell.

Example

This example shows how to determine the position of a TD object. Although the TD object appears to the far right in the document, its position is close to the x-axis and y-axis, because its offset parent is a TABLE object rather than the document body.

Note For Internet Explorer 4.0, this same example returns a position of 0,0 because the offset parent is the table row.

Sample Code

<HTML>
<HEAD>
  <TITLE>Elements: Positions</TITLE>
  <SCRIPT LANGUAGE="JScript">

  function showPosition()
  {
    var oElement = document.all.oCell;
    
    alert("The TD element is at (" + oElement.offsetLeft + 
          "," + oElement.offsetTop + ")\n" + "The offset parent is " 
          + oElement.offsetParent.tagName );
  }
  </SCRIPT>
</HEAD>
<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.</TD>
  </TR>
</TABLE>
</BODY>
</HTML>

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
A, ACRONYM, ADDRESS, APPLET, AREA, B, BDO, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, COMMENT, custom, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, Hn, HR, 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, LISTING, MAP, MARQUEE, MENU, NEXTID, NOBR, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, RT, RUBY, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP

See Also

Measuring Element Dimension and Location



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.