Chủ sở hữu DOM XML
❮ Đối tượng nút
Thí dụ
Đoạn mã sau tải " books.xml " vào xmlDoc và trả về phần tử gốc của nút <title> đầu tiên:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x =
xmlDoc.getElementsByTagName("title")[0].ownerDocument;
document.getElementById("demo").innerHTML =
"Nodename:
" + x.nodeName +
" (nodetype: " + x.nodeType + ")"
}
Đầu ra của đoạn mã trên sẽ là:
Nodename: #document (nodetype: 9)
Định nghĩa và Cách sử dụng
Thuộc tính ownerDocument trả về phần tử gốc (đối tượng tài liệu) cho một nút.
Cú pháp
nodeObject.ownerDocument
❮ Đối tượng nút