Ai
1 Star 0 Fork 12

NextZero/dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
_isAncestor.js 792 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yaohaixiao 提交于 2023-10-13 17:06 +08:00 . chore: 发布 1.0.0
/**
* 判断某个 DOM 元素是否为另一个 DOM 节点的祖先节点
* ========================================================================
* @method _isAncestor
* @see https://developer.mozilla.org/zh-CN/docs/Web/API/Node/compareDocumentPosition
* @param {HTMLElement} ancestor
* @param {HTMLElement} descendent
* @return {Boolean}
* @private
*/
const _isAncestor = (ancestor, descendent) => {
let result = false
if (!ancestor || !descendent || !ancestor.nodeType || !descendent.nodeType) {
return result
}
if (ancestor.contains && ancestor !== descendent) {
result = ancestor.contains(descendent)
} else {
result = !!(ancestor?.compareDocumentPosition(descendent) & 16)
}
return result
}
export default _isAncestor
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/nextzero/dom.js.git
git@gitee.com:nextzero/dom.js.git
nextzero
dom.js
dom.js
main

搜索帮助