---
id: javascript-dom-event-listener
title: "JavaScript DOM Event Listener"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["addEventListener", "removeEventListener", "event listener", "event bubbling", "event capturing", "useCapture"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.89
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["javascript", "js", "web", "frontend", "w3schools", "dom"]
raw_sources: ["https://www.w3schools.com/js/js_htmldom_eventlistener.asp"]
applied_in: []
github_commit: ""
---

# [[JavaScript DOM Event Listener]]

## 🎯 한 줄 통찰 (One-line insight)
`addEventListener()` attaches an event handler to an element without overwriting existing handlers, keeping JavaScript separate from HTML markup. [S1]

## 🧠 핵심 개념 (Core concepts)
- **Attach without overwriting** — `addEventListener()` attaches an event handler to the specified element without overwriting existing handlers. [S1]
- **Multiple handlers allowed** — you can add many handlers of the same type, and handlers for different event types, to one element. [S1]
- **Separation of concerns** — using `addEventListener()` separates the JavaScript from the HTML markup for better readability. [S1]
- **Bubbling vs capturing** — the optional `useCapture` parameter selects event propagation order; `true` means capturing, the default `false` means bubbling. [S1]
- **Removable** — `removeEventListener()` detaches a previously attached handler. [S1]

## 🧩 추출된 패턴 (Extracted patterns)
- **Named handler** — pass a function name to react with reusable logic. [S1]
- **Anonymous handler** — pass an inline function for one-off logic. [S1]
- **Parameter passing** — wrap the call in an anonymous function to pass parameters to a handler. [S1]

## 📖 세부 내용 (Details)
**The addEventListener() method** [S1]
The method attaches an event handler to the specified element without overwriting existing handlers. [S1]

**Syntax** [S1]
```javascript
element.addEventListener(event, function, useCapture);
```
The first parameter is the event type (e.g. `"click"` or `"mousedown"`), the second is the function to call, and the third (`useCapture`) is optional. [S1]

**Add an Event Handler to an Element** [S1]
Attach a named handler: [S1]
```javascript
document.getElementById("myBtn").addEventListener("click", displayDate);
```
Anonymous function handler: [S1]
```javascript
element.addEventListener("click", function(){ alert("Hello World!"); });
```
Named function handler: [S1]
```javascript
element.addEventListener("click", myFunction);

function myFunction() {
  alert ("Hello World!");
}
```

**Add Many Event Handlers to the Same Element** [S1]
Multiple handlers of the same type: [S1]
```javascript
element.addEventListener("click", myFunction);
element.addEventListener("click", mySecondFunction);
```
Handlers for different event types: [S1]
```javascript
element.addEventListener("mouseover", myFunction);
element.addEventListener("click", mySecondFunction);
element.addEventListener("mouseout", myThirdFunction);
```

**Add an Event Handler to the window Object** [S1]
The `addEventListener()` method lets you add listeners on any HTML DOM object such as the `window` object. [S1]

**Passing Parameters** [S1]
Wrap the call in an anonymous function to pass parameters: [S1]
```javascript
element.addEventListener("click", function(){ myFunction(p1, p2); });
```

**Event Bubbling or Event Capturing?** [S1]
The `useCapture` parameter controls propagation. Capturing (`true`) handles the outer element first; bubbling (`false`, default) handles the inner element first: [S1]
```javascript
document.getElementById("myP").addEventListener("click", myFunction, true);
document.getElementById("myDiv").addEventListener("click", myFunction, true);
```

**The removeEventListener() method** [S1]
Removes a handler attached with `addEventListener()`: [S1]
```javascript
element.removeEventListener("mousemove", myFunction);
```

## 🛠️ 적용 사례 (Applied in summary)
The page's snippets — attaching `displayDate` to a button click, anonymous and named handlers, multiple/different-type handlers, parameter passing, capturing handlers, and `removeEventListener` — are the canonical applied examples. No external project/commit applications found in the source.

## 💻 코드 패턴 (Code patterns)
Attach a handler (language: JavaScript):
```javascript
document.getElementById("myBtn").addEventListener("click", displayDate);
```
Pass parameters:
```javascript
element.addEventListener("click", function(){ myFunction(p1, p2); });
```
Remove a handler:
```javascript
element.removeEventListener("mousemove", myFunction);
```

## ⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
- Use a **named handler** when the logic is reusable or you need to `removeEventListener()` it later (the same function reference is required to remove). [S1]
- Use an **anonymous handler** for short one-off logic, or to **pass parameters** by wrapping the real call. [S1]
- Set `useCapture` **`true`** for capturing (outer-to-inner) and leave it **`false`/default** for bubbling (inner-to-outer). [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
No contradictions found in the source.

## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.89
- **중복 검사 결과:** 신규 생성 (New discovery)

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[JavaScript Tutorial]]
- **관련 개념:** [[JavaScript HTML Events]], [[JavaScript HTML DOM]], [[JavaScript DOM Methods]], [[JavaScript DOM Changing CSS]]
- **참조 맥락:** The script-side mechanism for wiring behavior to events, extending the inline-handler approach.

## 📚 출처 (Sources)
- [S1] W3Schools — JavaScript DOM Event Listener — https://www.w3schools.com/js/js_htmldom_eventlistener.asp

## 📝 변경 이력 (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript DOM Event Listener" page (Astra wiki-curation, P-Reinforce v3.1 format).
