JSPM

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

Get the parents of the element, optionally filtered by a selector.

Package Exports

  • dom-parents

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-parents) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dom-parents

Get the parents of the element, optionally filtered by a selector.

Usage

import getParents from 'dom-parents';

getParents(document.querySelector('#main'), '.cat').forEach((element) => {
  element.style.backgroundColor = '#008800';
})
import getParents from 'dom-parents';

document.querySelectorAll('.animal').forEach((element) => {
  element.addEventListener('mousedown', () => {
    const isBobAnimal = getParents(this, '.animals').length !== 0;
    if (isBobAnimal) {
      console.log('Bob is animal');
    } else {
      console.log('Bob is spy!');
    }
  });
});