Name
parentElement — NN n/a IE 4 DOM n/a
Synopsis
Read-only
Returns a reference to the next outermost element in the HTML
containment hierarchy. An element’s HTML parent is not
necessarily the same as the object returned by the
offsetParent
property. The
parentElement
concerns itself strictly with source
code containment, while the offsetParent
property
looks to the next outermost element that is used as the coordinate
system for measuring the location of the current element. For
example, if the main document contains a P
element
with an EM
element nested inside, the
EM
element has two parents. The
P
element is the returned
parentElement
value (due to the HTML source code
containment), while the BODY
element is the
returned offsetParent
value (due to coordinate
space containment).
You can jump multiple parent levels by cascading
parentElement
properties, as in:
document.all.elementID
.parentElement.parentElement
You can then use references to access a parent element’s properties or methods.
Example
document.all.elementID
.parentElement.style.font-size = "14pt"
Value
Element object reference.
Default
None.
Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.