DOM Event
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Event Listener</title>
<link rel="stylesheet" href="style.css" />
<script src="./script.js" defer></script>
</head>
<body>
<div class="grandparent">
<div class="parent">
<div class="child"></div>
</div>
</div>
</body>
</html>Add Event(์ด๋ฒคํธ ๋ฑ๋ก): addEventListener
๋์ ๊ธฐ๋ฅ(์ฌ์ฉ์ ์ ๋ ฅ ๋ฑ) ์ถ๊ฐ
document.addEventListener("click", (e) => { console.log("Document", e.target); });

Event Capturing(์ด๋ฒํธ ์บก์ฒ๋ง)
Capture In์ด๋ฒคํธ๊ฐ ๋ฐ์ํ์ ๋ ํ์ ์์๋ก ์ด๋ฒคํธ ์ ๋ฌ
Document>HTML>body>div>button(event target)addEventListener์capture:true์ต์ ์ถ๊ฐ
Event Bubbling(์ด๋ฒํธ ๋ฒ๋ธ๋ง)
Bubble Out์ด๋ฒคํธ๊ฐ ๋ฐ์ํ์ ๋ ์์ ์์๋ก ์ด๋ฒคํธ ์ ๋ฌ
button(event target) >div>body>HTML>Document
stopPropagation
์ด๋ฒคํธ ์ ๋ฌ ๋ฐฉ์ง
option: once
ํ๋ฒ๋ง ์คํํ๊ณ ์ ๊ฑฐ
addEventListener์once:true์ต์ ์ถ๊ฐ
Remove Event(์ด๋ฒคํธ ์ ๊ฑฐ): removeEventListener
ํ ๋น๋ ์ด๋ฒคํธ ์ ๊ฑฐ
Event Delegation(์ด๋ฒคํธ ์์)
์ด๋ฒคํธ ์บก์ฒ๋ง๊ณผ ๋ฒ๋ธ๋ง ํ์ฉํ์ฌ ์ด๋ฒคํธ ์์ ๊ตฌํ
์์๋ง๋ค ์ด๋ฒคํธ ํธ๋ค๋ฌ๋ฅผ ํ ๋นํ์ง ์๊ณ , ์์ ์์์์ ํ์ ์์์ ์ด๋ฒคํธ ์ ์ด
Reference
Last updated