# dom-closest

> For a given DOM element, find the first ancestor that matches a given CSS selector.

Latest version **0.2.0** (published 2015-08-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install dom-closest
pnpm add dom-closest
yarn add dom-closest
bun add dom-closest
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2015-08-18 |
| First published | 2014-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Nicolas Gallagher |
| Maintainers | necolas |
| Keywords | browser, closest, dom, element |

## Links

- npm: https://www.npmjs.com/package/dom-closest
- Repository: https://github.com/necolas/dom-closest
- Homepage: https://github.com/necolas/dom-closest#readme
- Issues: https://github.com/necolas/dom-closest/issues
- npm.io page: https://npm.io/package/dom-closest

## Dependencies (1)

- [dom-matches](https://npm.io/package/dom-matches.md) >=1.0.1

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2015-08-18
- 0.1.0 — 2014-12-19

## README

# dom-closest

[![Build Status](https://secure.travis-ci.org/necolas/dom-closest.png?branch=master)](http://travis-ci.org/necolas/dom-closest)

For a given DOM element, find the first ancestor that matches a given CSS
selector.

## Installation

```
npm install dom-closest
```

## API

### closest(elem, selector[, context])

* `element` (Element): a starting DOM Element.
* `selector` (String): the CSS selector of the ancestor to find.
* `context` (Element): a DOM node to use as search context (optional).

```js
var closest = require('dom-closest');

var photo = document.querySelector('.photo');
var timeline = document.querySelector('.timeline');

closest(photo, '.tweet');
// => Element

closest(photo, '.tweet', timeline);
// => Element
```

## Browser support

* Google Chrome
* Firefox 4+
* Internet Explorer 8+
* Safari 5+
* Opera

---
_Source: https://npm.io/package/dom-closest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
