20220616 개발일지

신유지·2022년 6월 16일

학습한 내용

1. 요소 노드 만들기

et newP = document.createElement("p")

2. 텍스트 노드 만들기

let newText = document.createTextNode("주문이 완료되었습니다.")

3. 자식 노드로 추가하기

newP.appendChild(newText)

4. 자식 노드로 추가하기

document.body.appendChild(newP

5. 속성 노드 만들기

let attr = document.createAttribute("class")
attr.value = "accent"

6. 속성 노드 연결하기

newP.setAttributeNode(attr)

또는 5, 6단계 대신: 텍스트 노드를 만들어 웹 문서에 추가해 놓은 경우 setAttribute()함수 사용하면 더 간단.

newP.setAttribute("class", "accent")

->전부 어렵지만 삭제기능이 제일 어려웠다.
부모노드를 2번 넣은 이유는 삭제할 요소가
P '이름' span x 이기 때문에 부모요소가 2번이 들어가야
p전체가 삭제된다.

->#myText를 클릭할때 글자크기, 글자색, 배경색을 바꾸는 코드

profile
성장하는 developer

0개의 댓글