Find the closest parent that matches a selector
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.md
component.json
index.js Update index.js Feb 5, 2013
package.json

README.md

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