offsetParent

HTML (DHTML)

offsetParent Property

Internet Development Index

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

oElement Object that receives the container object.

The property is read-only. The property has 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. For Internet Explorer 4.0, this same example returns a position of 0,0 because the offset parent is the table row.

<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>

Standards Information

There is no public standard that applies to this property.

Applies To

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, 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