This is the object that contains the receiving Element object. For example, an Element object that represents a <TABLE> tag is the parentElement of the Element objects that represent the <TR> tags within that table. If you want to add a row to a table, you may select the row that needs to be replaced or that it can be inserted after. You can then locate its parent Element and modify that if necessary.
This is not the same as the offsetParent. This property reflects the true document hierarchy in all its fine detail. The offsetParent property reflects the spatial relationships between objects. Objects that show up in the parentElement hierarchy will likely be omitted from the offsetParent hierarchy model on account of them not contributing any spatial offset to the contained elements.
Access to a parent element is especially useful when driving the generation of styleSheet properties. You might have a series of nested containers which cascade a relative font size. By checking the fonts size property belonging to the style object associated with the parent Element, you can set a limit on this cascading effect to prevent the font sizes from becoming too small.
Prev | Home | Next |
Element.ownerDocument | Up | Element.parentNode |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |