The DOM Event Model

The DOM Event Model

12月 30, 2023 · 1 分钟阅读时长 · 82 字 · -阅读 -评论

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

Alan H
Authors
开发者,数码产品爱好者,喜欢折腾,喜欢分享,喜欢开源