GitXplorerGitXplorer
e

find-parent

public
6 stars
6 forks
14 issues

Commits

List of commits on branch master.
Unverified
8ba1a9b63d7b486e9a775ce2c957f410b3d42087

chore(package): update wealthfront-javascript to version 4.0.0 (#59)

ggreenkeeper[bot] committed 8 years ago
Unverified
3373ca2035a64ac11a5eb6457727dd9ae4de8307

chore(package): update karma-chrome-launcher to version 2.0.0 (#58)

ggreenkeeperio-bot committed 8 years ago
Unverified
8b595d97356c384bb5de7c0ac7828dad4c587c91

chore(package): update mocha to version 3.0.2 (#57)

ggreenkeeperio-bot committed 8 years ago
Unverified
40cf71078a3faf45818599c54a6baa9c957b383b

2.0.3

eelicwhite committed 9 years ago
Unverified
142f2081a2501208e2ff2fb27ec71c7acd98a9a4

Updating deps and using babel (#54)

eelicwhite committed 9 years ago
Unverified
9da4b18bd2e56e4059c939914dd2013f0d2642b2

chore(package): update karma-mocha to version 1.0.1 (#37)

ggreenkeeperio-bot committed 9 years ago

README

The README file for this repository.

find-parent

Build Status devDependency Status

Find-parent is a utility to help find the closest element up an element's parent tree (possibly including itself) that matches certain rules.

Installation

$ npm install find-parent --save-dev

Usage

The examples below will use this as an example DOM structure.

<div class="foo">
  <span id="test" data-test-node="test">
    <a href="http://google.com">link text</a>
  </span>
</div>

byMatcher(element, func, opts)

var findParent = require('find-parent');

var element = document.getElementsByTagName('a')[0];

var result = findParent.byMatcher(element, function(node) {
  return node.className === 'foo';
});

// result is === to the element <div class="foo">

byClassName(element, className, opts)

var findParent = require('find-parent');

var element = document.getElementsByTagName('a')[0];

var result = findParent.byClassName(element, 'foo');

// result is === to the element <div class="foo">

withDataAttribute(element, attName, opts)

var findParent = require('find-parent');

var element = document.getElementsByTagName('a')[0];

var result = findParent.withDataAttribute(element, 'testNode');

// result is === to the element <span id="test" data-test-node="test">

Options

All findParent functions take an optional options argument.

key value type default description
throwOnMiss boolean false Throw error if no matching parent is found