append와 appendChild에 대해 알아보자
append와 appendChild의 공통점
- 부모 노드에 자식 노드를 추가하는 메소드
- 메서드를 호출한 노드의 마지막 자식 노드로 추가
append와 appendChild의 차이점
appendChild
- appendChild는 노드 객체만 추가할 수 있음
- 문자열 추가하면 에러 발생
- return값을 반환해줌
const myLi = document.createElement('li');
const myP = document.createElement('p');
myP.appendChild('text');
myP.innerText = 'text';
myLi.appendChild(myP);
append
- append는 노드 객체 뿐 아니라 문자열도 추가할 수 있음
- 한번에 2개 이상의 자식 노드를 추가할 수 있음
- return값을 반환하지 않음
const myLi = document.createElement('li');
const myP = document.createElement('p');
myP.append('text1');
myLi.append(myP,'text2');
console.log(myLi)