Table of contents
Summary
Indicates whether a node is a descendent of a given node.
Syntax
node.contains( otherNode )
nodeis the node that's being compared.otherNodeis the node that's being compared against.
The return value is true if otherNode is a descendent of node, or node itself. Otherwise the return value is false.
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);
}
nodeis the node we want to check for in the<body>.
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | 9.0 (9.0) | (Yes) | ? | (Yes) |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | ? | 9.0 (9.0) | ? | ? | ? |


Mozilla Developer Network