Is "mySPAN" a descendant of "myDIV"?
const span = document.getElementById("mySPAN");
let answer = document.getElementById("myDIV").contains(span);
Try it Yourself »
The contains()
method returns true
if a node is a descendant of a node.
The contains()
method returns false
if not.
A descendant can be a child, grandchild, great-grandchild, ...
node.contains(
node)
Parameter | Description |
node | Required. The node that may be a descendant of the node. |
Type | Description |
Boolean | true - The node is a descendantfalse - The node is NOT a descendant |
element.contains()
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!