Node.parentNode

  • Revision slug: DOM/Node.parentNode
  • Revision title: Node.parentNode
  • Revision id: 29915
  • Created:
  • Creator: Fguisset
  • Is current revision? No
  • Comment Adding a notes section, with a clarification of the behavior for non element nodes

Revision Content

{{template.DomRef()}}

Summary

The parentNode property returns the parent of the current element.

Syntax

pElement = element.parentNode

Parameters

  • pElement is the element parent of the current node.

Example

text_field = document.getElementById("t");
if ( div1.parentNode == document ){ 
    text_field.setAttribute("value", "top-level"); 
    // textfield displays text "top-level" }

Notes

parentNode returns null' for the following node types : Attr, Document, DocumentFragment, Entity and Notation. It also returns null if the node has just been created and is not yet attached to the tree.

Specification

parentNode

Revision Source

<p>
{{template.DomRef()}}
</p>
<h3 name="Summary">Summary</h3>
<p>The <b>parentNode</b> property returns the parent of the current element. 
</p>
<h3 name="Syntax">Syntax </h3>
<pre class="eval"><i>pElement</i> = element.parentNode
</pre>
<h3 name="Parameters">Parameters </h3>
<ul><li> <code>pElement</code> is the <code>element</code> parent of the current node.
</li></ul>
<h3 name="Example">Example </h3>
<pre>text_field = document.getElementById("t");
if ( div1.parentNode == document ){ 
    text_field.setAttribute("value", "top-level"); 
    // textfield displays text "top-level" }
</pre>
<h3 name="Notes">Notes </h3>
<p><i>parentNode</i> returns <i>null' for the following node types : Attr, Document, DocumentFragment, Entity and Notation. It also returns </i>null<i> if the node has just been created and is not yet attached to the tree.</i>
</p>
<h3 name="Specification">Specification </h3>
<p><a class="external" href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1060184317">parentNode </a>
</p>
Revert to this revision