# no-selector-as-dom-name

Rule `unicorn/no-selector-as-dom-name`. Disallow selector syntax in DOM names.

- Source: unicorn
- Technologies: JavaScript
- Kind: correctness
- 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: #1047 by reach, #1302 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-selector-as-dom-name` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-selector-as-dom-name.md) |

## Code examples

### Incorrect: the rule reports this

```js
element.classList.add('.active');
element.classList.remove('.hidden');
element.classList.contains('.selected');
element.classList.toggle('.expanded');
element.classList.replace('.old', '.new');
document.getElementsByClassName('.item');
document.getElementById('#app');
```

### Correct: the rule accepts this

```js
element.classList.add('active');
element.classList.remove('hidden');
element.classList.contains('selected');
element.classList.toggle('expanded');
element.classList.replace('old', 'new');
document.getElementsByClassName('item');
document.getElementById('app');
```

Examples from the ESLint documentation.

## Enable it

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

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

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-selector-as-dom-name": "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% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/no-optional-chaining-on-undeclared-variable](https://lintradar.dev/rules/unicorn/no-optional-chaining-on-undeclared-variable.md): Disallow optional chaining on undeclared variables.
- [unicorn/no-top-level-side-effects](https://lintradar.dev/rules/unicorn/no-top-level-side-effects.md): Disallow top-level side effects in exported modules.
- [unicorn/no-object-methods-with-collections](https://lintradar.dev/rules/unicorn/no-object-methods-with-collections.md): Disallow `Object` methods with `Map` or `Set`.
- [unicorn/no-uncalled-method](https://lintradar.dev/rules/unicorn/no-uncalled-method.md): Disallow referencing methods without calling them.
- [unicorn/no-non-function-verb-prefix](https://lintradar.dev/rules/unicorn/no-non-function-verb-prefix.md): Disallow non-function values with function-style verb prefixes.
- [unicorn/no-undeclared-class-members](https://lintradar.dev/rules/unicorn/no-undeclared-class-members.md): Require class members to be declared.

---

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