HTML DOM Element contains() method
- Προηγούμενη Σελίδα compareDocumentPosition()
- Επόμενη Σελίδα contentEditable
- Επιστροφή στο Πάνω Στρώμα HTML DOM Elements Οντόντο
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. May be a node that is 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 |
Υποστήριξη | 9-11 | Υποστήριξη | Υποστήριξη | Υποστήριξη | Υποστήριξη |
- Προηγούμενη Σελίδα compareDocumentPosition()
- Επόμενη Σελίδα contentEditable
- Επιστροφή στο Πάνω Στρώμα HTML DOM Elements Οντόντο