dom-closest
For a given DOM element, find the first ancestor that matches a given CSS selector.
Last updated 9 years ago by necolas .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install dom-closest 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.2.0                                ...           latest (9 years ago)

2 Versions

  • 0.2.0                                ...           9 years ago
  • 0.1.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (7)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |