概述
Node.contains()返回的是一个布尔值,来表示传入的节点是否为该节点的后代节点。
语法
node.contains( otherNode )
node
是否包含otherNode节点.otherNode
是否是node的后代节点.
如果 otherNode
是 node 的后代节点或是
node
节点本身.则返回true
, 否则返回 false
.
例子
下面的函数用来检查一个元素是否是body元素的后代元素且非body元素本身.
function isInPage(node) { return (node === document.body) ? false : document.body.contains(node); }
node
是我们想要检查的元素节点.
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | 9.0 (9.0) | 5.0 | (Yes) | (Yes) |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 9.0 (9.0) | ? | ? | ? |