1.0.2 • Published 9 years ago
descended-from v1.0.2
Descended From
Check if a DOM node is descended from another node or selector.
Installation
npm install descended-fromUsage
var descendedFrom = require('descended-from');
var child = document.getElementById('child');
var parent = document.getElementById('parent');
descendedFrom(child, parent) // -> truegiven 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') // -> truegiven 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') // -> truegiven 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