all
alt
ch
dir
id
min
rel
top
url
URL
urn
Expand Minimize

offsetTop property

Retrieves the calculated top position of the object relative to the layout or coordinate parent, as specified by the offsetParent property.

Syntax

JavaScript

p = object.offsetTop

 

Property values

Type: Integer

the top position, in pixels.

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.

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 Dynamic HTML (DHTML) Document Object Model (DOM), see Measuring Element Dimension and Location with CSSOM in Internet Explorer 9.

Examples

This example uses the offsetTop property to determine whether an object is in the user's view.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/offsetTop.htm


<html>

<head>
<script type="text/javascript">
function isinView(oObject)
{
    var oParent = oObject.offsetParent; 
    var iOffsetTop = oObject.offsetTop;
    var iClientHeight = oParent.clientHeight;
    if (iOffsetTop > iClientHeight) {
        alert("Special Text not in view. Expand Window to put Text in View.");
    }
    else{
         alert("Special Text in View!");
    }
}
</script>
</head>

<body onload="window.resizeTo(430,250)" onclick="isinView(oID_1)" scroll="NO">

<div style="position: absolute; left: 20px">
    Click anywhere in window to see if special text is in view.</div>
<div id="oID_1" style="position: absolute; 
    left: 50px; 
    top: 300px; 
    width: 280px; 
    color: silver; 
    font-size: large; 
    font-weight: bold; 
    background-color: aqua; 
    font-family: Arial">
    Here&#39;s some special text </div>

</body>

</html>

See also

a
abbr
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=email
input type=file
input type=image
input type=number
input type=password
input type=radio
input type=range
input type=reset
input type=search
input type=submit
input type=tel
input type=text
input type=url
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
TextRange
tFoot
th
tHead
tr
tt
u
ul
var
xmp
Reference
boundingHeight
boundingLeft
boundingTop
boundingWidth

 

 

Show:
© 2014 Microsoft