# better-dom-traversing

Rule `unicorn/better-dom-traversing`. Prefer better DOM traversal APIs.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #905 by reach, #1160 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/better-dom-traversing` | no | suggestion | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/better-dom-traversing.md) |
| Biome | `nursery/useBetterDomTraversing` | no | unsafe | group nursery, since 2.5.13 | [docs](https://biomejs.dev/linter/rules/use-better-dom-traversing/) |

## Code examples

### Incorrect: the rule reports this

```js
element.childNodes[0];
```

```js
element.children[0];
```

```js
element.children[2];
```

### Correct: the rule accepts this

```js
element.firstChild;
```

```js
element.firstElementChild;
```

```js
element.querySelector(':scope selector');
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/better-dom-traversing": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "useBetterDomTraversing": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-top-level-await](https://lintradar.dev/rules/unicorn/prefer-top-level-await.md): Prefer top-level await over top-level promises and async function calls.
- [unicorn/no-canvas-to-image](https://lintradar.dev/rules/unicorn/no-canvas-to-image.md): Prefer drawing canvases directly instead of converting them to images.
- [unicorn/prefer-string-raw](https://lintradar.dev/rules/unicorn/prefer-string-raw.md): Prefer using the `String.raw` tag to avoid escaping `\`.
- [unicorn/no-collection-bracket-access](https://lintradar.dev/rules/unicorn/no-collection-bracket-access.md): Disallow accessing `Map`, `Set`, `WeakMap`, and `WeakSet` entries with bracket notation.
- [unicorn/no-useless-iterator-to-array](https://lintradar.dev/rules/unicorn/no-useless-iterator-to-array.md): Disallow unnecessary `.toArray()` on iterators.
- [unicorn/no-constant-zero-expression](https://lintradar.dev/rules/unicorn/no-constant-zero-expression.md): Disallow arithmetic and bitwise operations that always evaluate to `0`.

---

Web page: https://lintradar.dev/rules/unicorn/better-dom-traversing. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
