XML DOM parentNode attribute
Definition and Usage
The parentNode attribute returns the parent node of the specified node.
Syntax:
elementNode.parentNode
Example
In all examples, we will use the XML file books.xml, and JavaScript functions loadXMLDoc().
The following code snippet retrieves the parent node of the first <title> element in "books.xml":
xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName("title")[0];
var parent=x.parentNode
;
document.write("Parent node: " + parent.nodeName);
The output of the above code:
Parent node: book