Tags

DOM Manipulation

DOM Manipulation

0 lessons
4 code snippets
8 question banks
6 community items

js-dom

Code Snippets

4 snippets
Code Snippet

Copy Text to the Clipboard

Every dashboard, share modal, and code-block UI eventually needs a copy button. The modern path is `navigator.clipboard.writeText`, but it requires a secure context and a user gesture, so a robust helper falls back to a hidden `<textarea>` when the API is unavailable. This snippet covers the modern call, the legacy fallback, and a copy-with-toast helper that wraps both behind a single async function.

JavaScript
js-web-apis
js-dom
utility
code-template

290

4

Easy
Code Snippet

Read a URL Query Parameter

Reading `?q=hello` is a one-liner with `URLSearchParams`, but the helpers around it (multi-value params, defaults, type coercion, updating without reload) are where most apps end up duplicating code. This snippet covers the basic read, a typed-default helper, and a setter that updates the URL with `history.replaceState` so the back button keeps working. Use it for filters, search inputs, and shareable links.

JavaScript
js-web-apis
js-dom
utility
code-template

415

12

Easy
Code Snippet

Trigger a File Download from a Blob

Generating a CSV, JSON export, or screenshot client-side and saving it without a server round-trip is a five-line trick: build a `Blob`, mint an object URL, click a hidden `<a download>`, and revoke the URL. This snippet covers the canonical helper, a JSON export wrapper, and the cleanup pattern that prevents memory leaks during long-running sessions.

JavaScript
js-web-apis
js-dom
utility
blob-storage

699

16

Medium
Code Snippet

Check if an Element Is in the Viewport

Lazy-loading images, animating sections on enter, and infinite scroll all start with the same question: is this element on screen? The classic answer was a scroll handler plus `getBoundingClientRect`, but `IntersectionObserver` is now the right tool: passive, batched, and rate-limited by the browser. This snippet covers the synchronous bounds check, the async observer-based watcher, and a one-shot helper that resolves once a target enters the viewport.

JavaScript
js-web-apis
js-dom
performance-optimization
utility

512

11

Medium

Question Banks

8 items
Question Bank

Event Delegation and Event Bus Quiz

Practice DOM event delegation, build a minimal pub/sub event bus, and roll your own dispatcher so cross-component communication stays decoupled.

JavaScript
quiz
js-event-delegation
js-dom
design-patterns

569

10

Medium
Question Bank
Premium

DOM Observer APIs Quiz (IntersectionObserver, MutationObserver)

Use the three DOM observer APIs the browser ships for free: IntersectionObserver for visibility, MutationObserver for DOM diffs, and ResizeObserver for layout changes.

JavaScript
quiz
js-web-apis
js-dom
performance-optimization

517

13

Hard
Question Bank

Controlled vs Uncontrolled Components Quiz

Four checks on the controlled / uncontrolled split for React form inputs, including the file-input edge case and the warning React emits when you flip between defaultValue and value.

JavaScript
quiz
react
hooks
js-dom

491

4

Medium
Question Bank

React Portals, Fragments, and StrictMode Quiz

Three drills on three small but tested React features: portals (with their event bubbling quirk), fragments, and what StrictMode does in development.

JavaScript
quiz
react
interview-prep
js-dom

296

8

Medium
Question Bank

React Synthetic Events and Event Pooling Quiz

Three drills on React's SyntheticEvent wrapper, how delegation works, and the difference between the React 16 pooling era and React 17+ behavior.

JavaScript
quiz
react
js-event-delegation
js-dom

906

8

Medium
Question Bank

JavaScript Cross-Browser Event Target: Two Approaches Quiz

Two seeded approaches to read the event target across browsers (event.target plus legacy event.srcElement, and a delegated table cell editor), plus two companions on currentTarget and composedPath.

JavaScript
quiz
js-event-delegation
js-dom
js-language

340

7

Medium
Question Bank

React Controlled vs Uncontrolled Components: Two Explanations Quiz

Two explanations of controlled vs uncontrolled inputs with concrete code, plus companions on `defaultValue` and on extending the controlled idea beyond form inputs.

JavaScript
quiz
react
hooks
js-dom

977

16

Easy
Question Bank
Premium

React Portals: Two Explanations Quiz

Two explanations of React portals (mechanics and use cases, plus event bubbling through the virtual tree) with companions on a Modal implementation and a portal-aware focus trap.

JavaScript
quiz
react
js-dom
interview-prep

844

23

Hard

Community

6 items
Code Snippet

IntersectionObserver Batched With rootMargin

On a feed with 200 cards, creating one IntersectionObserver per card pushed our scroll frame to 14ms. This is the single shared observer with `rootMargin` prefetch and a batched callback that brought it back to 4ms.

JavaScript
intersection-observer
js-dom
performance
frontend

500

9

Apr 9, 2026

by @emmakim

Question Bundle
Free

The React Form Validation Traps I Keep Stepping On

Hand-rolled forms in React look easy until they meet real users. These 5 traps are the ones I keep regressing on: the empty-input case, controlled vs uncontrolled, when to stop hand-rolling, async race conditions, and the accessibility bit nobody catches in review.

JavaScript
react
hooks
js-dom
interview-prep

795

3

4.2 (15)

Apr 4, 2026

by @zurihayes

Article

Understanding Event Propagation: Capturing, Bubbling, and More

The three-phase event model in the DOM, why bubbling is the default for historical reasons, when capturing pays off, and how event delegation falls out of the same mechanic.

js-event-delegation
html-events
js-dom
interview-prep
fundamentals

862

25

4.4 (13)

Feb 23, 2026

by @hannahchakraborty

Code Snippet

Paste-Image-From-Clipboard Handler

When a user hits Cmd-V with a screenshot in their clipboard, we want to upload it as if they had drag-dropped. This is the 30-line paste handler I keep, including the Safari-only `clipboardData.items` traversal and a graceful HEIC fallback.

JavaScript
js-dom
frontend
code-template

956

28

4.2 (10)

Jan 14, 2026

by @rajreeves

Code Snippet

A File Drop Zone Without a Library

The drop zone I keep instead of pulling in react-dropzone (60+kB minified): drag-over visuals, multi-file drops, folder uploads via DataTransferItem, and the Safari quirk where dragleave fires on every child enter.

JavaScript
js-dom
code-template
frontend
utility

323

1

4.4 (13)

Dec 6, 2025

by @isabellarashid

Code Snippet

The Three Ref-Driven Scroll Hooks I Actually Use

Four ref recipes that earn their keep: `scrollIntoView`, deps-driven scroll-to-top, multi-target callback refs in a Map, and the `forwardRef` + `useImperativeHandle` escape hatch.

JavaScript
react
hooks
references
js-dom

618

12

4.4 (15)

Nov 26, 2025

by @rajtanaka