DOM Events

This topic covers the moment a browser tells your code something happened. Listener options, capture and bubble phases, delegated handlers over a changing list, cleanup when a node disappears, passive scroll listeners, and visibility signals that pause work while a tab is hidden all live here. Examples name the target element they expect and show whether the handler runs during capture or bubble. Browse the task groups to separate attaching a listener from controlling one you already own, then read each explanation for the propagation and memory behaviour that determines whether the pattern survives a real page with widgets, navigation, and long-lived components that mount and unmount repeatedly during normal use.

In scope: Include examples where the central difficulty is receiving, scoping, delegating, or removing a browser event. Out of scope: Exclude layout-only or data-only examples that happen to run inside a click handler.

10 published examples across 5 primary task groups. Read the group heading to find the task you are solving, then pick the Example whose assumptions match your page.

Build a responsive layout

1 example

Arrange boxes so the design holds across viewport widths, zoom levels, and content growth.

Handle DOM events

3 examples

Attach, configure, delegate, and remove browser event listeners correctly.

Observe element visibility

2 examples

React to intersection, viewport entry, or document visibility changes.

Structure page content

3 examples

Mark up document regions, reading order, and navigation so people and crawlers share one map.

Validate form input

1 example

Decide whether entered data is acceptable and report the result to the person filling the form.

Adjacent navigation