Skip to content

Type Editor


Type Editor / @type-editor/dom-util / node-size

node-size

Functions

FunctionDescription

nodeSize

Gets the size of a DOM node.

For text nodes (nodeType 3), returns the length of the text content. For element nodes, returns the number of child nodes.

Example

typescript
const textNode = document.createTextNode("Hello");
const size = nodeSize(textNode); // Returns 5

const element = document.createElement("div");
element.appendChild(document.createElement("span"));
const elemSize = nodeSize(element); // Returns 1