XML DOM parentNode attribute
Definition and usage
The parentNode attribute can return the parent node of a node.
Syntax:
nodeObject.parentNode
Example
In all examples, we will use the XML file books.xml, and JavaScript function loadXMLDoc().
The following code snippet can return the parent node of the first <title> element:
xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName("title")[0];
var parent=x.parentNode
;
document.write("Parent node: " + parent.nodeName);
Output:
Parent node: book