
DomParentNode::append 함수는 주어진 노드를 현재 노드의 자식 노드 목록의 끝에 추가합니다.
이 함수는 노드를 추가한 후 현재 노드를 반환합니다.
예를 들어, 다음과 같은 HTML 구조가 있다고 가정해 보겠습니다.
#hostingforum.kr
html
자식 노드 1
자식 노드 2
#hostingforum.kr
javascript
const parent = document.getElementById('parent');
const newNode = document.createElement('p');
newNode.textContent = '새로운 자식 노드';
parent.appendChild(newNode);
이 코드는 새로운 `
` 요소를 생성하고, 그 요소를 `#parent` 요소의 자식 노드 목록의 끝에 추가합니다.
이 함수의 반환 값은 추가된 노드의 부모 노드 인 `#parent` 요소 자체입니다.
#hostingforum.kr
javascript
console.log(parent); // #parent 요소
이러한 반환 값을 사용하여, 추가된 노드를 쉽게 참조할 수 있습니다.
2025-05-09 20:29