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).
var closest = ; var photo = document;var timeline = document; ;// => Element ;// => Element
Browser support
- Google Chrome
- Firefox 4+
- Internet Explorer 8+
- Safari 5+
- Opera