The DOM Event Model

Quick refresher on the DOM event flow (capture → target → bubble), key JS methods, and references.

Dec 30, 2023 · 1 min read · 82 Words · -Views -Comments · Digital Life
JavaScript DOM 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

I’ve been wiring up keyboard shortcuts lately and needed a quick refresher on DOM events.

Event Flow Visualization

JavaScript APIs

  1. Binding events is straightforward. Use addEventListener, and pass the third argument to opt into the capture phase. For pure bubbling, handlers like onclick work too.
  2. The event.stopPropagation() method halts propagation—whether the event is bubbling or capturing—exactly as the diagram shows.
  3. event.preventDefault() doesn’t stop propagation, but it blocks default behaviors such as following a link when clicking an <a> tag.

References

done

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover