HTML DOM contains() Method
Example
Find out if a <span> element is a descendant of a <div> element:
var span = document.getElementById("mySPAN");
var div =
document.getElementById("myDIV").contains(span);
The result of div will be:
true
Try it yourself »
Definition and Usage
The contains() method returns a Boolean value indicating whether a node is a descendant of a specified node.
A descendant can be a child, grandchild, great-grandchild, and so on.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
contains() | Yes | 5.0 | 9.0 | 3.0 | Yes |
Syntax
node.contains(node)
Parameter Values
Parameter | Description |
---|---|
node | Required. Specifies the node that may be contained by (a descendant of) a specified node |
Technical Details
Return Value: |
A Boolean, indicating whether a node is a descendant of a specified node:
|
---|