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 »
Definition and Usage
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 | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |