Skip to content

Commit

Permalink
Merge pull request #1230 from publdaze/publdaze
Browse files Browse the repository at this point in the history
39-3μž₯ DOM - 김은지
  • Loading branch information
Ryan-Dia authored Jan 18, 2024
2 parents 332d0b7 + e45f03a commit 4c9e68d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/39_DOM/김은지.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,36 @@ DOM(Document Object Model)
- λ…Έλ“œ 객체의 상속 κ΅¬μ‘°λŠ” 개발자 도ꡬ Elements>Properties νŒ¨λ„μ—μ„œ 확인 κ°€λŠ₯
- DOM은 HTML λ¬Έμ„œμ˜ 계측적 ꡬ쑰와 정보λ₯Ό ν‘œν˜„ν•˜λŠ” 것은 λ¬Όλ‘  λ…Έλ“œ 객체의 μ’…λ₯˜, 즉 λ…Έλ“œ νƒ€μž…μ— 따라 ν•„μš”ν•œ κΈ°λŠ₯을 ν”„λ‘œνΌν‹°μ™€ λ©”μ„œλ“œ 집합인 DOM API둜 μ œκ³΅ν•œλ‹€.
- DOM APIλ₯Ό 톡해 HTML κ΅¬μ‘°λ‚˜ λ‚΄μš© λ˜λŠ” μŠ€νƒ€μΌ 등을 λ™μ μœΌλ‘œ μ‘°μž‘ν•  수 μžˆλ‹€.

### 39.2 μš”μ†Œ λ…Έλ“œ 취득

**39.2.4 CSS μ„ νƒμžλ₯Ό μ΄μš©ν•œ μš”μ†Œ λ…Έλ“œ 취득**

- CSS μ„ νƒμž : μŠ€νƒ€μΌμ„ μ μš©ν•˜κ³ μž ν•˜λŠ” HTML μš”μ†Œλ₯Ό νŠΉμ •ν•  λ•Œ μ‚¬μš©ν•˜λŠ” 문법
- Document.prototype/Element.prototype.querySelector λ©”μ„œλ“œ - 인수둜 μ „λ‹¬ν•œ CSS μ„ νƒμžλ₯Ό λ§Œμ‘±μ‹œν‚€λŠ” ν•˜λ‚˜μ˜ μš”μ†Œ λ…Έλ“œ 탐색 및 λ°˜ν™˜
- Document.prototype/Element.prototype.querySelectorAll λ©”μ„œλ“œ - 인수둜 μ „λ‹¬ν•œ CSS μ„ νƒμžλ₯Ό λ§Œμ‘±μ‹œν‚€λŠ” λͺ¨λ“  μš”μ†Œ λ…Έλ“œ 탐색 및 λ°˜ν™˜
- Document.prototype에 μ •μ˜λœ λ©”μ„œλ“œλŠ” DOM μ „μ²΄μ—μ„œ μš”μ†Œ λ…Έλ“œλ₯Ό νƒμƒ‰ν•˜μ—¬ λ°˜ν™˜ν•˜κ³ , Element.prototype에 μ •μ˜λœ λ©”μ„œλ“œλŠ” νŠΉμ • μš”μ†Œ λ…Έλ“œμ˜ μžμ† λ…Έλ“œ μ€‘μ—μ„œ μš”μ†Œ λ…Έλ“œλ₯Ό νƒμƒ‰ν•˜μ—¬ λ°˜ν™˜ν•œλ‹€.
- 단점 - getElementById, getElementBy\*\*\* λ©”μ†Œλ“œλ³΄λ‹€ λ‹€μ†Œ λŠλ¦¬λ‹€.
- μž₯점 - CSS μ„ νƒμž 문법을 μ‚¬μš©ν•˜μ—¬ μ’€ 더 ꡬ체적인 쑰건으둜 μš”μ†Œ λ…Έλ“œλ₯Ό 취득할 수 있고 μΌκ΄€λœ λ°©μ‹μœΌλ‘œ μš”μ†Œ λ…Έλ“œλ₯Ό 취득할 수 μžˆλ‹€.
=> πŸ’‘ id μ–΄νŠΈλ¦¬λ·°νŠΈκ°€ μžˆλŠ” μš”μ†Œ λ…Έλ“œλ₯Ό μ·¨λ“ν•˜λŠ” κ²½μš°μ—λŠ” getElementById λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜κ³  κ·Έ μ™Έμ˜ κ²½μš°μ—λŠ” querySelector, querySelectorAll λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜λŠ” 것을 ꢌμž₯ν•œλ‹€.

**39.2.5 νŠΉμ • μš”μ†Œ λ…Έλ“œλ₯Ό 취득할 수 μžˆλŠ” 지 확인**

- Element.prototype.matches λ©”μ„œλ“œ
- 인수둜 μ „λ‹¬ν•œ CSS μ„ νƒμžλ₯Ό 톡해 νŠΉμ • μš”μ†Œ λ…Έλ“œλ₯Ό 취득할 수 μžˆλŠ” 지 ν™•μΈν•œλ‹€.
- 이벀트 μœ„μž„μ„ μ‚¬μš©ν•  λ•Œ μœ μš©ν•˜λ‹€.

**39.2.6 HTMLCollectionκ³Ό NodeList**

- HTMLCollectionκ³Ό NodeListλŠ”
- DOM APIκ°€ μ—¬λŸ¬ 개의 결과값을 λ°˜ν™˜ν•˜κΈ° μœ„ν•œ DOM μ»¬λ ‰μ…˜ 객체닀.
- λ…Έλ“œ 객체의 μƒνƒœ λ³€ν™”λ₯Ό μ‹€μ‹œκ°„μœΌλ‘œ λ°˜μ˜ν•˜λŠ” μ‚΄μ•„μžˆλŠ”(live) κ°œμ²΄λ‹€.
- HTMLCollection은 μ–Έμ œλ‚˜ live 객체둜 λ™μž‘ν•œλ‹€.
- NodeListλŠ” λŒ€λΆ€λΆ„μ˜ 경우 non-live 객체둜 λ™μž‘ν•˜μ§€λ§Œ κ²½μš°μ— 따라 live 객체둜 λ™μž‘ν•  λ•Œκ°€ μžˆλ‹€.
- HTMLCollection
- getElementsByTagName, getElementsByClassName λ©”μ„œλ“œκ°€ λ°˜ν™˜ν•œλ‹€.
- μ‹€μ‹œκ°„μœΌλ‘œ λ…Έλ“œ 객체의 μƒνƒœ 변경을 λ°˜μ˜ν•˜μ—¬ μ˜€μ†Œλ₯Ό μ œκ±°ν•  수 있기 λ•Œλ¬Έμ— for 문으둜 μˆœνšŒν•˜λ©΄μ„œ λ…Έλ“œ 객체의 μƒνƒœλ₯Ό λ³€κ²½ν•΄μ•Ό ν•  λ•Œ μ£Όμ˜ν•΄μ•Ό ν•œλ‹€. -> for 문을 μ—­λ°©ν–₯으둜 μˆœνšŒν•˜λŠ” λ°©λ²•μ΄λ‚˜ while 문을 μ‚¬μš©ν•΄ λ…Έλ“œ 객체가 남아 μžˆμ§€ μ•Šμ„ λ•ŒκΉŒμ§€ λ¬΄ν•œ λ°˜λ³΅ν•˜λŠ” λ°©λ²•μœΌλ‘œ νšŒν”Όν•  수 μžˆλ‹€. --> HTMLCollection 객체λ₯Ό μ‚¬μš©ν•˜μ§€ μ•Šκ³ , λ°°μ—΄λ‘œ λ³€ν™˜ν•˜λ©΄ 더 κ°„λ‹¨ν•œ ν•΄κ²°μ±…!
- NodeList
- HTMLCollection 객체 λΆ€μž‘μš© 해결을 μœ„ν•΄ getElementsByTagName, getElementsByClassName λ©”μ„œλ“œ λŒ€μ‹  querySelectorAll λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜λŠ” 방법도 μžˆλ‹€.
- querySelectorAll λ©”μ„œλ“œκ°€ λ°˜ν™˜ν•˜λŠ” NodeList κ°μ²΄λŠ” non-live 객체닀.
- childNodes ν”„λ‘œνΌν‹°κ°€ λ°˜ν™˜ν•˜λŠ” NodeList κ°μ²΄λŠ” live 객체둜 λ™μž‘ν•œλ‹€.

0 comments on commit 4c9e68d

Please sign in to comment.