HTML DOM Element contains() method
- Previous Page compareDocumentPosition()
- Next Page contentEditable
- Go Back to the Previous Level HTML DOM Elements Object
Definition and usage
If the node is a descendant of a node, then contains()
The method returns true
.
otherwise,contains()
The method returns false
.
Note:Descendants can be children, grandchildren, great-grandchildren, etc.
Example
Is "mySPAN" a descendant of "myDIV"?
const span = document.getElementById("mySPAN"); let answer = document.getElementById("myDIV").contains(span);
Syntax
node.contains(node)
Parameter
Parameter | Description |
---|---|
node | Required. A node that may be a descendant of the node. |
Return value
Type | Description |
---|---|
Boolean | true - The node is a descendant false - The node is not a descendant
Browser support
element.contains()
It is a DOM Level 1 (1998) feature.
All browsers fully support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous Page compareDocumentPosition()
- Next Page contentEditable
- Go Back to the Previous Level HTML DOM Elements Object