PROPERTY:  Object::parentNode

Object  Attr   CDATASection   CharacterData   Comment   Document   DocumentFragment   DocumentType   Entity   EntityReference   Node   Notation   ProcessingInstruction   Text
 
Object.parentNode

The parentNode property which is read-only returns returns the parent node of all nodes except Document, DocumentFragment and Attr, which cannot have parent nodes. Also, a node that is newly-created and not yet added to a tree, or one that has been removed from a tree cannot have a parent node either.

The example that follows first gets the firstChild of the root node of the 'states.xml' file and then that node's parent node (the root node). It displays the node names of both.

XML:
<States>
   <State ref="FL">
      <name>Florida</name>
      <capital>Tallahassee</capital>
   </State>
   <State ref="IA">
      <name>Iowa</name>
      <capital>Des Moines</capital>
   </State>
</States>

Code (JavaScript):
var xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("states.xml");

var n = xml_doc.documentElement.firstChild;
document.write(n.nodeName);
var p_node = n.parentNode;
document.write("<br>" + p_node.nodeName);

Output:
State
States



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information