Node.contains() 方法返回 布尔 value indicating whether a node is a descendant of a given node, i.e. the node itself, one of its direct children ( childNodes ), one of the children's direct children, and so on.

句法

node.contains( otherNode )
					

范例

This function checks to see if an element is in the page's body. As 包含 is inclusive and determining if the body contains itself isn't the intention of isInPage this case explicitly returns false .

function isInPage(node) {
  return (node === document.body) ? false : document.body.contains(node);
}
					

规范

规范 状态 注释
DOM
The definition of 'Node.contains()' in that specification.
实时标准 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
包含 Chrome 16 Edge 12 Firefox 9 IE 9
9
Only supports 包含 for HTML elements and not for SVG elements.
Opera 7 Safari 1.1 WebView Android ≤37 Chrome Android 18 Firefox Android 9 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0

图例

完整支持

完整支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: