referrer : 직전 유입 경로
cookie : 쿠키값 조회 / HttpOnly로 설정된 쿠키는 조회 불가
요소와 요소 사이에 있는 공백 문자의 영향을 받습니다.
parentNodechildNodesfirstChildlastChildnextSiblingpreviousSiblingnodeTypenodeValuenodeName상대적으로 선택하는 방법
children : 자식 요소들 parentElement : 부모 요소firstElementChild : 첫번째 자식 요소 선택 lastElementChild : 마지막 자식 요소 선택 nextElementSibling : 오른쪽 형제 요소 previousElementSibling : 왼쪽 형제 요소 childElementCount : 자식 요소 갯수head : document.head
body : document.body
렌더링 엔진은 DOM 트리와 스타일 규칙이 바뀔 때마다 렌더 트리를 다시 구성해서 웹페이지를 다시 그립니다.
id(단일), class(복수) -> 선택을 위한 속성
document.getElementById("아이디명")
document.getElementsByTagName("태그 이름")
document.getElementsByClassName("클래스명")
document.getElementsByName("name 속성명")
document.querySelector("CSS 선택자") : 한개만 선택
document.querySelectorAll("CSS 선택자") : 복수개 선택
속성 : 태그에 있는 추가 정보
어떤 속성은 태그의 기능과 관련된 정보를 담고 있다. (예 - type, src, href ...)
getAttribute("속성명")
setAttribute("속성명, "속성값")
hasAttribute("속성명")
removeAttribute("속성명")
attributes
많이 사용하는 속성들은 각 요소의 document 객체 하위 속성으로 바로 접근 가능
id, type, src, href, target, action, name 등등...class(❌) 👉 className정보성 속성에는 관례로
data-속성명 = "값"형식으로 명칭을 정해야한다.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<input type="text" id="price" data-price="10000">
</body>
</html>
dataset 객체 : 속성명으로 바로 접근 가능
삭제 : delete 연산자

priceEl.dataset.goodsName = "상품명";
자동으로 앞에 data가 붙여서 저장됨.
<input type="text" id="price" data-price="20000" data-goods-name="상품명">
delete 연산자
delete priceEl.dataset.price;
add(...) : 클래스 추가remove(...) : 클래스 제거contains(...) : 클래스가 있는지 여부toggle(...) : 클래스가 있으면 제거, 없으면 추가
priceEl.classList.add("cls4"); //추가
priceEl.classList.remove("cls4"); //삭제
priceEl.classList.containts("cls3"); >> true //포함 여부
priceEl.classList.toggle("cls4") // 있으면 제거, 없으면 추가
const headerEl = document.getElementById("header");
innerText: document 객체 안쪽 텍스트만 반환(태그는 제외)
textContent : doucument 객체 안쪽 텍스트만 변환(태그는 제외)document.createElement("태그명");
document.createTextNode("텍스트");
const liEl = document.createElement("li");
liEl;
<li></li>
const testEl = document.createTextNode("메뉴4");
testEl;
메뉴4
const liEl = document.createElement("li");
const textEl = document.createTextNode("메뉴4");
liEl.appendChild(textEl);
const menusEl = document.getElementById("menus");
menusEl.appendChild(liEl);

const liEl = document.createElement("li");
liEl.appendChild(document.createTextNode("메뉴1-2"));
const menusEl = document.getElementById("menus");
const liEl2 = menusEl.children[1];
menusEl.insertBefore(liEl, liEl2);

도큐먼트 객체는 한가지만 존재하기 때문에, appendChild를 사용하더라도 새로 복사가 되는것이 아니라, 노드가 옮겨지고 트리구조가 재생성되어진다.
const menusEl = document.getElementById("menus");
undefined
const menu1El = menusEl.children[0];
undefined
menu1El;
menus.appendChild(menu1El);

removeChild(..)
const menusEl = document.getElementById("menus");
undefined
const menu2El = menusEl.children[1];
undefined
menusEl.removeChild(menu2El);

부모를 선택하고 바로 자식을 삭제
const menu2El = document.getElementById("menu2");
menu2El.parentElement.removeChild(menu2El);
replaceChild(...)