JSPM

dom-closest

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 78571
  • Score
    100M100P100Q154647F
  • License MIT

For a given DOM element, find the first ancestor that matches a given CSS selector.

Package Exports

  • dom-closest

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dom-closest) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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