XML DOM parentNode 속성
❮ 노드 객체
예시
다음 코드 조각은 " 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];
document.getElementById("demo").innerHTML =
"Parent
node: " + x.parentNode.nodeName;
}
위 코드의 출력은 다음과 같습니다.
Parent node: book
정의 및 사용
parentNode 속성은 노드의 부모 노드를 반환합니다.
통사론
nodeObject.parentNode
❮ 노드 객체