XML DOM appendChild() 메서드
❮ 노드 객체
예시
다음 코드 조각은 " books.xml "을 xmlDoc에 로드하고 노드(<edition>)를 만들고 첫 번째 <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 newel =
xmlDoc.createElement("edition");
var x =
xmlDoc.getElementsByTagName("book")[0];
x.appendChild(newel);
document.getElementById("demo").innerHTML =
x.getElementsByTagName("edition")[0].nodeName;
}
위 코드의 출력은 다음과 같습니다.
edition
정의 및 사용
appendChild() 메서드는 노드의 자식 목록 끝에 새 자식 노드를 추가합니다.
참고: newchild 가 이미 트리에 있으면 먼저 제거됩니다 .
브라우저 지원
appendChild() 메서드는 모든 주요 브라우저에서 지원됩니다.
통사론
nodeObject.appendChild(newchild)
Parameter | Description |
---|---|
newchild | The node to add (append) |
반환 값
Type | Description |
---|---|
Node object | The appended node |
기술적 세부 사항
DOM 버전 | 코어 레벨 1 노드 개체. DOM 레벨 3에서 수정됨 |
---|
직접 체험해볼 수 있는 데모
❮ 노드 객체