Join MDN and developers like you at Mozilla's View Source conference, November 2-4 in Portland, Oregon. Learn more at

The Node.contains() method returns a Boolean value indicating whether a node is a descendant of a given node or not.


node.contains( otherNode ) 


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);


Specification Status Comment
The definition of 'Node.contains()' in that specification.
Living Standard Initial definition

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 9.0 (9.0) 5.0[1] (Yes) 3.0[2]
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? 9.0 (9.0) ? ? ?

[1] Internet Explorer only supports contains() for elements.

[2] Safari 2.x implemented contains() incorrectly.

See also

Document Tags and Contributors

Last updated by: Sebastianz,