Web APIs
Node.contains()
Returns whether the other node is the receiver itself or one of its descendants.
Formal Syntax & Structure
javascript syntaxjavascript
node.contains(otherNode)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| otherNode | Node | null | Candidate 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));