clo

closest

Find the closest parent that matches a selector

Showing:

Popularity

Downloads/wk

31.1K

GitHub Stars

27

Maintenance

Last Commit

4yrs ago

Contributors

4

Package

Dependencies

1

Size (min+gzip)

0.3KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

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:

var closest = require('closest');

closest(document.body, 'html') === document.documentElement
closest(document.body, 'body', true) === document.body
closest(document.documentElement, 'html') == null

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial