문서객체모델
html문서의 각 요소들을 트리 형식으로 표현,트리형식의 자료구조

자바스크립트를 이용해 이를 생성,수정,삭제 가능
위 그림에서 하나의 객체가 노드
document.documentElement //html 접근
document.body //body태그 접근
document.head
document.body.style
모든 html태그는 객체임.
자바스크립트로 접근할 수 있다.
자바스크립트로 html제어가 가능함
document.body.style.opacity ='0.5';//투명도
document.body.style.padding = '100px';
document.getElementById('first');
document.getElementsByTagName('p');
태그명으로도 접근 가능함
let pList = document.getElementsByTagName('p');
for(p of pList){
p.style.fontSize = '30px';
}
+)id는 한페이지에 1번만 사용가능하기에 getElement가 단수형
p태그는 여러개니까 복수형
document.getElementByClassName()
document.getElementByName()
document.querySelectorAll('.link');//클래스접근
document.querySelectorAll('#first');//id접근
document.querySelector('#first');//id는 어차피 하나니깐
querySelector는 제일 처음의 노드만 가져옴
document.querySelector('h3:nth-of-type(2)');//두번째 h3찾기
document.querySelector('h3:nth-of-type(2)').style.color='red';//찾아서 빨간색으로 변경
let pList = document.querySelectorAll('p:nth-of-type(2n)');//짝수번째 p태그
for(p of pList){
p.style.backgroundColor ='#000';
p.style.color='#fff';
}//p태그 번갈아가며 흑백바꾸기

querySelectorAll, getElementBy는 반환값이 조금 다름

querySelectorAll는 NodeList를 반환
getElementBy는 HTMLCollection을 반환
공통점 ; 둘다 유사배열객체, 이터러블, for of순회가능
차이점

p태그 추가하고 다시 찍어보면
pList2만 값이 변함
html컬랙션은 노드의 변경사항이 실시간으로 반영
const red = document.getElementById('red');
red.parentNode;//부모노드접근
red.parentElement;//부모노드접근
document.documentElement; //html
document.documentElement.parentNode;//#document
document.documentElement.parentElement;//null
parentNode는 부모노드를 반환, html의 부모노드는 도큐먼트
parentElement는 부모노드중 요소노드만 반환
const ul = document.getElementById('color');
ul.childNodes;
ul.children; //요소노드만 반환

childNodes는 li요소 외에도 text, 주석 등 모든 타입의 노드를 반환함.
text는 공백도포함
children는 요소타입의 노드들만 반환
childNodes는 NodeList를 반환하지만, 예외적으로 html컬랙션처럼 실시간 반영됨.
ul.firstChild;
ul.lastChild;
ul.firstElementChild;
ul.lastElementChild;
형제노드 접근
이전형제, 다음형제로 나뉨
형제노드중 모든 타입가져옴
const blue = document.getElementById('blue');
blue.previousSibling;
blue.nextSibling;
blue.previousElementSibling;
blue.nextElementSibling;

이런 유용한 정보를 나눠주셔서 감사합니다.