THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML DOM contains() Method

Element Object Reference Element Object

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 Yes Yes Yes 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:
  • true - The node is a descendant
  • false - The node is NOT a descendant

Element Object Reference Element Object