-
firstChild vs firstElementChild개발/Javascript 2022. 1. 30. 02:42
<div> <ul> <li></li> </ul> </div>
위와 같은 DOM 구조가 있다고 할 때 ul은 div의 firstChild일까요 firstElementChild일까요? 이름에서 대략적으로 유추할 수 있듯이 firstElementChild입니다. 각 태그가 Element이거든요. firstChild의 경우 Element를 포함한 모든 Node를 가리킵니다. <div>와 <ul> 사이에는 공백(whitespace)가 존재하며 공백은 #text 노드를 만들기 때문에 firstChild를 출력해보면 #text가 나타납니다.
'개발 > Javascript' 카테고리의 다른 글
location.hash (0) 2022.01.30 append (0) 2022.01.30 [npm] install flags (0) 2022.01.26 [vscode] ESLint airbnb 플러그인 + etc (0) 2022.01.26 [vscode] Prettier가 인식이 잘 안 될 때 (0) 2022.01.26