XML DOM ownerElement 屬性
❮ Attr 物件
示例
以下程式碼片段將“books.xml”載入到 xmlDoc 中,並返回第一個 category 屬性所附加到的元素節點
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('book');
document.getElementById("demo").innerHTML =
x.item(0).attributes[0].ownerElement + "<br>" +
x.item(0).attributes[0].ownerElement .nodeName + "<br>" +
x.item(0).attributes[0].ownerElement .nodeType;
}
上面程式碼的輸出將是
[object Element]
書
1
自己動手試一試 »
定義和用法
ownerElement 屬性返回屬性所附加到的元素節點。
語法
attrObject.ownerElement
❮ Attr 物件