10 out of 16 rated this helpful - Rate this topic

offsetParent property

[This documentation is preliminary and is subject to change.]

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

Syntax

JavaScript

p = object.offsetParent

Property values

Type: Object

the container object.

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 Microsoft Internet Explorer 4.0 it returns the tr object. You can use the parentElement property to retrieve the immediate container of the table cell.

Examples

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.


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

See also

a
abbr
acronym
address
applet
area
article
aside
b
bdo
big
blockQuote
body
br
button
caption
center
cite
code
col
colGroup
custom
dd
del
dfn
dir
div
dl
dt
em
embed
fieldSet
figcaption
figure
font
footer
form
frame
frameSet
head
header
hgroup
hn
hr
html
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
isIndex
kbd
label
legend
li
listing
map
mark
marquee
menu
nav
nextID
noBR
object
ol
optGroup
option
p
plainText
pre
q
rt
ruby
s
samp
section
select
small
span
strike
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
tr
tt
u
ul
var
xmp
Measuring Element Dimension and Location with CSSOM in Internet Explorer 9

 

 

Build date: 3/8/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ