You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
3 weeks ago | |
---|---|---|
.. | ||
CHANGELOG.md | 3 weeks ago | |
LICENSE.md | 3 weeks ago | |
README.md | 3 weeks ago | |
index.js | 3 weeks ago | |
package.json | 3 weeks ago |
README.md
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 = 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