是否是指定节点的父级
const isDomParent = require('zhf.is-dom-parent');
isDomParent('html', 'body'));
isDomParent('body', 'html'));
isDomParent('body', 'html'));
isDomParent('html', 'html'));
isDomParent('body', 'body'));
isDomParent(document, 'body'));
isDomParent('body', document.querySelector('html')));
isDomParent(document.querySelector('body'), 'html'));
isDomParent(document, document.querySelector('body')));
isDomParent(document.querySelector('body'), document.querySelector('html')));
isDomParent(document.querySelector('html'), document.querySelector('body')));
isDomParent(document.querySelector('html'), document.querySelector('html')));
isDomParent(document.querySelector('body'), document.querySelector('body')));
- 原生js有个
parentDom.contains(childDom)
- 如果parentDom和childDom是同一个元素,返回的是true。
- jQuery有个
$.contains(parentDom, childDom)
- 如果parentDom和childDom是同一个元素,返回的是false(我借鉴了这点)。