XML DOM hasChildNodes() 메서드
❮ 노드 객체
예시
다음 코드 조각은 " books.xml "을 xmlDoc에 로드하고 첫 번째 <book> 요소에 자식 노드가 있는지 여부를 반환합니다.
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')[0];
document.getElementById("demo").innerHTML =
x.hasChildNodes();
}
위 코드의 출력은 다음과 같습니다.
true
정의 및 사용
hasChildNodes() 메서드는 지정된 노드에 자식 노드가 있으면 true 를 반환하고, 그렇지 않으면 false 를 반환 합니다.
브라우저 지원
hasChildNodes() 메서드는 모든 주요 브라우저에서 지원됩니다.
통사론
nodeObject.hasChildNodes()
매개변수
없음.
반환 값
Type | Description |
---|---|
Boolean | Returns true if the specified node has any child nodes, otherwise false |
기술적 세부 사항
DOM 버전 | 코어 레벨 1 노드 개체 |
---|
❮ 노드 객체