Check if a DOM node is descended from another node or selector.
npm install descended-from
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
.
var child = document.getElementById('child');
descendedFrom(child, '.parent') // -> true
given this DOM
<div class="parent">
<div>
<div id="child"></div>
</div>
</div>
var child = document.getElementById('child');
descendedFrom(child, '#parent') // -> true
given this DOM
<div id="parent">
<div>
<div id="child"></div>
</div>
</div>
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)
MIT