Document Object Model

html์ด ๋ฉ”๋ชจ์žฅ์—์„œ๋Š” ๊ทธ๋ƒฅ string์ด์ง€๋งŒ, browser์—์„œ๋Š” ํ•ด์„ํ•ด์„œ ๊ตฌ์กฐํ™”(DOMtree) ๋ฅผ ํ•ด์„œ DOM์ด ๋œ๋‹ค.

Console์—์„œ type of document ํ•  ์‹œ, ๊ฒฐ๊ณผ๋กœ object๊ฐ€ return ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

DOM ์กฐ์ž‘: parsing๋œ html, ์ฆ‰ DOM{~~~} DOM์•ˆ์˜ ๋‚ด์šฉ์„ ์กฐ์ž‘ํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•จ

It means ๋ฌธ์ž์—ดํƒ์ƒ‰ -> Tree ํƒ์ƒ‰ (Tree์˜ ํ•˜๋‚˜ํ•˜๋‚˜๋Š” Node๊ฐ€ ๋œ๋‹ค) / ์„œ๋ฒ„์—†์ด ์ •์ ์ธ ์ƒํƒœ์—์„œ๋„ Programmableํ•œ ๋ฌธ์„œ๊ฐ€ ๋  ์ˆ˜ ์žˆ๋‹ค. / MTV ๊ณผ์ • ์ƒ๋žตํ•˜๊ณ  browser๋ฅผ ์ฝ”๋”ฉํ•  ์ˆ˜ ์žˆ์Œ

  1. ์„ ํƒ 1. document.querySelector()

    Node๋ฅผ ์ฐพ์ž! / Element์—์„œ copy -> selector ๋กœ ''์œผ๋กœ ๋ฌถ์–ด ์ธ์ž๋ฅผ ๋„ฃ์–ด์ฃผ์ž: ์ฃผ์–ด๋ฅผ ์žก์Œ

    • .innerHTML

    • .classlist: parsingํ•ด์คŒ / .classlist.add: ๋™์ ์œผ๋กœ class๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Œ

  2. ์ˆ˜์ •

    • document.querySelector(์…€๋ ‰ํ„ฐ).innerText = "!!!"

  3. ์ƒ์„ฑ

    • point: ๋ฌธ์„œ์—์„œ ๋Œ€์ƒ์„ ์žก๊ณ , ์ˆ˜์ •ํ•˜๊ณ , ์ƒ์„ฑํ•˜๋Š”๋ฐ strํ•˜๋“œํƒ€์ดํ•‘ ๋ฐฉ์‹์ด ์•„๋‹Œ, ๊ฐ์ฒด ๋ฅผ ์žก์•„์„œ ์กฐ์ž‘ํ•˜์ž

  4. ์ด๋ฒคํŠธ๋ฆฌ์Šคํ„ฐ

    ์š”์†Œ.addEventListener('์ด๋ฒคํŠธ', ์ด๋ฒคํŠธ ๋ฐœ์ƒ์‹œ ์‹คํ–‰ํ•  ํ•จ์ˆ˜)

    myButton.addEventListener('click', confirmMessage)

    addEventListener์˜ ์ธ์ž์ธ ์‹คํ–‰ํ•จ์ˆ˜๋Š”, ๋“ฑ๋กํ•ด๋†“์€ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋Š๋‚Œ์œผ๋กœ ๊ฐ€์•ผํ•จ, ์‹คํ–‰ํ•จ์ˆ˜์˜ ์ธ์ž๋Š” ์ด๋ฒคํŠธ๊ฐ์ฒด์ž„

Last updated