XML DOM removeChild() 메서드
❮ 노드 객체
예시
다음 코드 조각은 " 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 root =
xmlDoc.documentElement;
var currNode = root.childNodes[1];
removedNode = currNode.removeChild(currNode.childNodes[1]);
document.getElementById("demo").innerHTML =
"Removed
node: " + removedNode.nodeName;
}
산출:
Removed node: title
정의 및 사용
removeChild() 메서드는 현재 노드에서 지정된 자식 노드를 제거합니다.
팁: 제거된 자식 노드는 나중에 같은 문서의 모든 요소에 삽입할 수 있습니다. insertBefore() 또는 appendChild() 메소드를 사용 하여 나중에 동일한 문서에 삽입하거나, acceptNode() 또는 importNode() 메소드를 사용하여 제거된 노드를 다른 문서에 삽입하십시오.
브라우저 지원
removeChild() 메소드는 모든 주요 브라우저에서 지원됩니다.
통사론
nodeObject.removeChild(child)
매개변수
Parameter | Type | Description |
---|---|---|
child | Node object | Required. The node to remove |
반환 값
Type | Description |
---|---|
Node object | Returns the removed node as a Node object |
기술적 세부 사항
DOM 버전 | 코어 레벨 1 노드 개체. DOM 레벨 3에서 수정됨 |
---|
❮ 노드 객체