Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/forbeslindesay/closest
Find the closest parent that matches a selector
https://github.com/forbeslindesay/closest
Last synced: 17 days ago
JSON representation
Find the closest parent that matches a selector
- Host: GitHub
- URL: https://github.com/forbeslindesay/closest
- Owner: ForbesLindesay
- Created: 2013-03-13T17:07:51.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-06-23T03:16:54.000Z (over 7 years ago)
- Last Synced: 2024-10-20T04:43:57.701Z (24 days ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 27
- Watchers: 5
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Closest
Finds the closest parent that matches a selector. Like `jQuery.fn.closest`
## Installation
$ npm install closest
## API
### `closest(element, selector, checkSelf)`
* `element` - element to search from
* `selector` - CSS selector to match parents
* `checkSelf`
* If falsey (default) it starts with the parent like `$(element).closest(selector)`
* If truthy it starts with itself so would return `element` if it matches `selector`Example:
```javascript
var closest = require('closest');closest(document.body, 'html') === document.documentElement
closest(document.body, 'body', true) === document.body
closest(document.documentElement, 'html') == null
```## License
MIT