firstChild
-
firstChild vs firstElementChild개발/Javascript 2022. 1. 30. 02:42
위와 같은 DOM 구조가 있다고 할 때 ul은 div의 firstChild일까요 firstElementChild일까요? 이름에서 대략적으로 유추할 수 있듯이 firstElementChild입니다. 각 태그가 Element이거든요. firstChild의 경우 Element를 포함한 모든 Node를 가리킵니다. 와 사이에는 공백(whitespace)가 존재하며 공백은 #text 노드를 만들기 때문에 firstChild를 출력해보면 #text가 나타납니다.