Range.commonAncestorContainer
Range.commonAncestorContainer
只读属性,返回目标节点的共有祖先节点。因而需要注意:selectNode 方法中的该值为目标节点的父节点,selectNodeContents 方法中的该值为其本身。
在某些跨节点的选取操作时,取得最大"公约数"的节点为commonAncestorContainer。
即Range.startContainer
和 Range.endContainer
相同的节点是目标节点的 共有祖先节点。
语法
rangeAncestor = range.commonAncestorContainer;
示例
var range = document.createRange();
range.setStart(startNode,startOffset);
range.setEnd(endNode,endOffset);
rangeAncestor = range.commonAncestorContainer;
特别说明
Specification | Status | Comment |
---|---|---|
DOM Range.commonAncestorContainer |
Living Standard | No change. |
Document Object Model (DOM) Level 2 Traversal and Range Specification Range.commonAncestorContainer |
Obsolete | Initial specification. |
支持度
BCD tables only load in the browser