--- id: javascript-html-events title: "JavaScript HTML Events" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["HTML events", "onclick", "onload", "event handlers", "JavaScript events"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 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_events.asp"] applied_in: [] github_commit: "" --- # [[JavaScript HTML Events]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) HTML events are things that happen to HTML elements, and JavaScript event handlers are the code that runs when those events occur. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **An event handler is code that runs on an event** β€” an event handler is JavaScript code that runs when an event happens. [S1] - **Events can call a function** β€” an event attribute can run JavaScript inline or call a named function. [S1] - **`this` refers to the element** β€” inside an inline handler, `this` refers to the element that received the event. [S1] - **addEventListener is the recommended approach** β€” attaching handlers with `addEventListener()` keeps JavaScript separate from the HTML markup. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Inline handler** β€” `onclick="..."` runs JavaScript directly in the HTML attribute. [S1] - **Function call handler** β€” `onclick="displayDate()"` delegates to a named function. [S1] - **Listener handler** β€” `element.addEventListener("click", fn)` attaches behavior from script. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **HTML Events** [S1] An HTML event can be something the browser does, or something a user does. JavaScript lets you execute code when events are detected. [S1] **JavaScript Events / Calling a JavaScript Function** [S1] A basic `onclick` handler running JavaScript inline: [S1] ```html ``` Using `this` to refer to the element itself: [S1] ```html ``` Calling a named function from the handler: [S1] ```html ``` **Common HTML Events** [S1] | Event | Description | |-------|-------------| | `onchange` | An HTML element has been changed | | `onclick` | The user clicks an HTML element | | `onmouseover` | The user moves the mouse over an HTML element | | `onmouseout` | The user moves the mouse away from an HTML element | | `onkeydown` | The user pushes a keyboard key | | `onload` | The browser has finished loading the page | **JavaScript Event Handlers** [S1] An event handler is JavaScript code that runs when an event happens. [S1] **Using an Event Listener** [S1] The recommended way to attach a handler from script is `addEventListener()`: [S1] ```html

``` ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's snippets β€” `onclick` writing `Date()`, `this.innerHTML`, a `displayDate()` function, and an `addEventListener("click", ...)` handler β€” are the canonical applied examples. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Inline handler (language: HTML): ```html ``` Function-call handler (language: HTML/JavaScript): ```html ``` Event listener (language: JavaScript): ```javascript const btn = document.getElementById("myBtn"); btn.addEventListener("click", function () { document.getElementById("demo").innerHTML = Date(); }); ``` ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) - Use **inline `on*` attributes** for quick, simple handlers written directly in the HTML. [S1] - Use **`addEventListener()`** when you want the JavaScript separated from the HTML markup for better readability and to attach multiple handlers. [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.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript DOM Event Listener]], [[JavaScript DOM Changing CSS]], [[JavaScript DOM Changing HTML]], [[JavaScript HTML DOM]] - **μ°Έμ‘° λ§₯락:** The event layer that triggers DOM content and style changes in response to user/browser actions. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript HTML Events β€” https://www.w3schools.com/js/js_events.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript HTML Events" page (Astra wiki-curation, P-Reinforce v3.1 format).