Handle a missing element explicitly
#querySelector returns the first match or null. TypeScript’s generic annotation describes the expected element type; it does not prove the HTML has that shape.
Fragment
Reference
Look up semantic HTML, forms, CSS layout, events, DOM operations and common browser APIs.
Modern browser platform examples, independent of a framework. HTML/CSS excerpts belong in the appropriate document/style context; DOM snippets assume a browser and named elements/data; TypeScript annotations clarify DOM types and need compilation or removal in plain JavaScript. Check target-browser support for newer features.
querySelector returns the first match or null. TypeScript’s generic annotation describes the expected element type; it does not prove the HTML has that shape.
Fragment
target is where the event originated; currentTarget is the current listener’s element during its invocation. Nested icon/text markup can make them differ.
Fragment
A parent can handle bubbling events from dynamic children. Check the target’s type and containment before using closest().
Fragment
Not every event bubbles. Shadow DOM retargeting and composed paths have additional rules.
preventDefault requests cancellation of a cancelable default action. stopPropagation stops further propagation; it does not cancel the default action.
Fragment
A passive listener cannot cancel its event’s default behavior.
An AbortSignal can own several event listeners. Aborting removes those listeners; it is separate from canceling any work their handlers already started.
Fragment