XML DOM ownerElement attribute

Definition and usage

The ownerElement attribute returns the element node attached to the attribute.

Syntax:

attrObject.ownerElement

Example

In all examples, we will use the XML file books.xml, and JavaScript function loadXMLDoc().

The following code snippet returns the element attached to the first category attribute:

xmlDoc=loadXMLDoc("/example/xdom/books.xml");
x=xmlDoc.getElementsByTagName('book');
document.write(x.item(0).attributes[0].ownerElement);
document.write("<br />");
document.write(x.item(0).attributes[0].ownerElement.nodeName);
document.write("<br />");
document.write(x.item(0).attributes[0].ownerElement.nodeType);

The output of the above code is:

[object Element]
book
1