document.contains
Version:
Polyfill/shim for `document.contains`
23 lines (19 loc) • 423 B
JavaScript
;
module.exports = function contains(other) {
if (arguments.length < 1) {
throw new TypeError('1 argument is required');
}
if (typeof other !== 'object') {
throw new TypeError('Argument 1 (”other“) to Node.contains must be an instance of Node');
}
var node = other;
do {
if (this === node) {
return true;
}
if (node) {
node = node.parentNode;
}
} while (node);
return false;
};