All Projects → necolas → dom-closest

necolas / dom-closest

Licence: MIT License
For a given DOM element, find the first ancestor that matches a given CSS selector.

Programming Languages

javascript
184084 projects - #8 most used programming language

dom-closest

Build Status

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].