Node.instanceOf method
Node › instanceOf
Official
Cross-window capable instanceof check, a drop-in replacement for instanceof checks on DOM Nodes. Remember to also check for nulls when necessary.Signature:
instanceOf(type: NodeConstructor<T>): this is TParameters:
| Parameter | Type | Description |
|---|---|---|
| type | NodeConstructor<T> | The type to check. |
Returns: this is T — true if the node is of the given type, false otherwise.
Example:
const node = createEl('p');console.log(node.instanceOf(HTMLParagraphElement)); // trueconsole.log(node.instanceOf(HTMLSpanElement)); // false