javascript Element parentElement

parentElement NN n/a IE 4 DOM n/a  

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.getElementById("elementID").parentElement.parentElement;

You can then use references to access a parent element's properties or methods.

The corresponding property for the W3C DOM is parentNode.

 
Example
 
document.getElementById("elementID").parentElement.style.fontSize = "14pt";
 
Value

Element object reference.

 
Default

Element-specific.


685,Nickname,Homepage or email,Comments here,Add comment