---
title: $
subpath: pota/use/test
topic: Internals
desc: querySelector with element type inferred from the selector.
---

# $

`$(selector, node?)` is shorthand for `querySelector`. The element
type is inferred from the selector's leading tag, so
`$('input[name="x"]')` typechecks as `HTMLInputElement | null`. Pass
an explicit type parameter to override, e.g.
`$<HTMLDivElement>('.my-class')`. For the all-matches array see
[`$$`](/use/test/$$). Part of [`pota/use/test`](/use/test).

## Arguments

| Argument   | Type                      | Description                                    |
| ---------- | ------------------------- | ---------------------------------------------- |
| `selector` | `string`                  | A CSS selector passed to `querySelector`.      |
| `node`     | `Document \| HTMLElement` | Root to search within. Defaults to `document`. |

**Returns:** the first matching element (type inferred from the
selector's leading tag), or `null`.
