* DOM (Document Object Model) : 문서 객체 모델
Node.nodeType docs
https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
const pList = document.querySelectorAll('p');
// NodeList가 출력된다.
// 값이 저장된다. (예외도 있음)
const pList = document.getElementsBytagName('p');
// HTMLCollection이 출력된다.
// 실시간으로 값을 추가하면 값이 변환된다.
* 부모 Node에 접근
const red = doucument.getElementById('red');
red.parentNode; // 부모 Node를 반환한다.
red.parentElement; // 부모 Node중에 HTMl tag로 이루어진 요소만 반환한다.
* 자식 Node에 접근
const ul = document.getElementById('color');
// 모든 type의 Node를 반환
// 공백 및 개행의 값까지 전부 포함되어서 나오기 때문에 더 많은 값이 나온다.
// childNodes는 html컬렉션과 같이 실시간으로 변경이 동작한다.
ul.childNodes;
// 요소(HTML tag)type의 Node들만 반환
ul.children;
ul.firstChild; // 첫번재 Node
ul.lastChild; // 마지막 Node
ul.firstElementChild; // 첫번째 요소 Node
ul.lastElementChild; // 마지막 요소 Node
* 형제 Node에 접근
const blud = document.getElementBuId('blue');
blue.previousSibling; // 이전 Node
blue.nextSibling; // 다음 Node
blue.previousElementSibling; // 이전 요소
blue.nextElementSibling; // 다음 요소
'Study > JavaScript' 카테고리의 다른 글
[JavaScript_study] DOM & EVENT 이벤트 핸들러(Event Handler) (0) | 2022.03.24 |
---|---|
[JavaScript_study] DOM & EVENT 노드 생성, 추가, 복제, 삭제 (0) | 2022.03.24 |
[JavaScript_study] Generator (0) | 2022.03.23 |
[JavaScript_study] 클로저 (Closure) (0) | 2022.03.23 |
[JavaScript_study] Rest parameters, Spread syntax (0) | 2022.03.23 |