XML DOM เจ้าของคุณสมบัติ เอกสาร
❮ วัตถุธาตุ
ตัวอย่าง
โค้ดย่อยต่อไปนี้โหลด " books.xml " ลงใน xmlDoc และรับชื่อและประเภทโหนดจากเอกสารเจ้าขององค์ประกอบ <title> แรก:
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 + ")"
}
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
Nodename: #document (nodetype: 9)
ความหมายและการใช้งาน
คุณสมบัติ ownerDocument ส่งคืนอ็อบเจ็กต์เอกสารที่เป็นองค์ประกอบที่เลือก
ไวยากรณ์
elementNode.ownerDocument
❮ วัตถุธาตุ