Web APIs

Node.contains()

Try the free JavaScript compiler

Returns whether the other node is the receiver itself or one of its descendants.

Formal Syntax & Structure

javascript syntaxjavascript
node.contains(otherNode)

Parameters & Attributes

NameTypeDescription
otherNodeNode | nullCandidate node.

Return Value

boolean

Whether node is contained.

Working Example

Example Snippetjavascript
const box=document.createElement("div"),inside=document.createElement("button"),outside=document.createElement("button");box.append(inside);console.log(box.contains(inside),box.contains(outside),box.contains(box));
JavaScript Reference