1.0.2 • Published 7 years ago

descended-from v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

Descended From

npm Build Status Coverage Status npm GitHub license

Check if a DOM node is descended from another node or selector.

Installation

npm install descended-from

Usage

var descendedFrom = require('descended-from');

var child = document.getElementById('child');
var parent = document.getElementById('parent');

descendedFrom(child, parent) // -> true

given this DOM

<div id="parent">
  <div>
    <div id="child"></div>
  </div>
</div>

This is equivalent running parent.contains(child). However you can do more with descended-from.

Check if descended from an element with a class

var child = document.getElementById('child');

descendedFrom(child, '.parent') // -> true

given this DOM

<div class="parent">
  <div>
    <div id="child"></div>
  </div>
</div>

Check if descended from an element with an ID

var child = document.getElementById('child');

descendedFrom(child, '#parent') // -> true

given this DOM

<div id="parent">
  <div>
    <div id="child"></div>
  </div>
</div>

Browser support

Chrome 1+, Firefox 3.5+, IE 9+, Opera 10.5+, Safari 5+

Browser functions depended on so far are:

  • element.classList()
  • element.contains()
  • string.trim()
  • string.charAt()
  • string.replace() (accepting string parameters)

License

MIT

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago