Node.contains()
The Node.contains() method returns a
Boolean value indicating whether a node is a descendant of a given node,
i.e. the node itself, one of its direct children (childNodes), one of the children's direct children, and so on.
Syntax
node.contains( otherNode )
Example
This function checks to see if an element is in the page's body. As
contains is inclusive and determining if the body contains itself isn't the
intention of isInPage this case explicitly returns false.
function isInPage(node) {
return (node === document.body) ? false : document.body.contains(node);
}Specifications
| Specification |
|---|
| DOM Standard (DOM) # ref-for-dom-node-contains① |
Browser compatibility
BCD tables only load in the browser