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 specifies the top position, in pixels. The property is read-only with 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 document object model, see Measuring Element Dimension and Location.
Example
This example uses the offsetTop property to determine whether an object is in the user's view.
Sample Code
<SCRIPT> function isinView(oObject) { var oParent = oObject.offsetParent; var iOffsetTop = oObject.offsetTop; var iClientHeight = oParent.clientHeight; if (iOffsetHeight > iClientHeight) { alert("Scroll down for the message."); } } </SCRIPT> : <BUTTON onclick="isinView(this)">Click here</BUTTON> : <DIV ID=oDiv STYLE="position:absolute; top:900; left:0;"> : </DIV>
Applies To
A, ACRONYM, ADDRESS, APPLET, AREA, B, BDO, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, 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=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, TextRange, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP