English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM contains() Method

HTML DOM Element Object

contains()Returns a boolean value indicating whether the node passed in is a child node of the current node.

Syntax:

node.contains(node)
var p = document.getElementById("myP");
var div = document.getElementById("myDIV");
div.contains(p);
Test to see‹/›

Browser Compatibility

All browsers fully support the contains() method:

Method
contains()YesYesYesYesYes

Parameter Value

ParameterDescription
nodeSpecify the node (and its descendants) that may contain the specified node

Technical Details

Return value:A boolean value indicating whether the node is a child of the given node.
Possible values:
  • true-The node is a descendant

  • false-The node is not a child node

HTML DOM Element Object