Skip to content
jshacks.dev
Debugging

Query elements in the console with double dollar

Use $$ in the DevTools console to get all matching elements as a real array, so map and filter work, and $ for the first match.

1 min read
Summarize in AI

document.querySelectorAll returns a NodeList, which has no map or filter. In the DevTools console, $$ runs the same query and returns a plain array.

JavaScript
$$("a").map((a) => a.href)
Text
(2) ['https://example.test/a', 'https://example.test/b']

$ is the matching shortcut for document.querySelector, so $("h1").textContent reads the first heading. Both take an optional second argument, the node to search in, as in $$("li", $0), which limits the search to the selected list. See the Console Utilities reference.

Combine them with the rest of the utilities. For example, copy($$("a").map((a) => a.href).join("\n")) puts every link on your clipboard.

If the page defines its own $ or $$, as jQuery or a framework does, the console uses the page's version instead, and the shortcut behaves differently. Check what $ is before trusting it.

Both exist only in DevTools. In page code, write document.querySelectorAll and use Array.from when you need array methods.

Share

More snippets

Debugging

Group related logs with console.group

Indent related console output under a label with console.group and console.groupEnd, so interleaved logs from one request stay readable in Node.js 24.

1 min read
Debugging

Inspect an object with console.dir

Show nested objects beyond the default depth of two with console.dir and the depth option, instead of the [Object] placeholders console.log prints.

1 min read
Debugging

Debug a single Vitest test in VS Code

Run one Vitest file under the VS Code debugger with a launch configuration that passes the open file, so breakpoints in tests and source work. Vitest 3.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.