Skip to content

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 T

Parameters:

Parameter Type Description
type NodeConstructor<T> The type to check.

Returns: this is Ttrue if the node is of the given type, false otherwise.

Example:

const node = createEl('p');
console.log(node.instanceOf(HTMLParagraphElement)); // true
console.log(node.instanceOf(HTMLSpanElement)); // false