HTML DOM Element contains()
Example
Is "mySPAN" a descendant of "myDIV"?
const span = document.getElementById("mySPAN");
let answer = document.getElementById("myDIV").contains(span);
Try it Yourself »
Description
The contains() method returns true if a node is a descendant of a node.
The contains() method returns false if not.
Note
A descendant can be a child, grandchild, great-grandchild, ...
Syntax
node.contains(node)
Parameters
| Parameter | Description |
| node | Required. The node that may be a descendant of the node. |
Return Value
| Type | Description |
| Boolean | true - The node is a descendantfalse - The node is NOT a descendant |
Browser Support
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 |