const elementNode = document.createElement('h1'); const textNode = document.createTextNode('Hello World!'); elementNode.appendChild(textNode); console.log(Node.isTextNode(textNode)); // true console.log(Node.isTextNode(elementNode)); // false
const node = document.querySelector('.container'); const childNodes = node.childNodes; for (let i = 0; i < childNodes.length; i++) { if (Node.isTextNode(childNodes[i])) { console.log(childNodes[i]); } }In this example, the `.container` element is selected from the DOM, and its child nodes are retrieved. A loop is then used to iterate over the child nodes, and `Node.isTextNode` is used to determine if each child node is a text node. If a child node is a text node, its contents are logged to the console. The `Node` object is a built-in object in the JavaScript language, and is not specific to a particular package or library.