From 227a9f97815d3ba7f5a4ee6182ffc82c93e3eab8 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Fri, 30 Oct 2020 19:44:30 +0530 Subject: [PATCH] element-properties - Clarify tagName for text nodes --- docs/element-properties.mdx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/element-properties.mdx b/docs/element-properties.mdx index beeb6f0..c708ca0 100644 --- a/docs/element-properties.mdx +++ b/docs/element-properties.mdx @@ -23,12 +23,14 @@ ele.tagName // "IMG" :::note Text nodes don't have `tagName` -Text nodes are not element, so they don't have any tagName - it'll just give `undefined`. +Text nodes are not element, so they don't have any tagName. +To identify the type of node, use `.nodeType` - which returns `3` (same as `Node.TEXT_NODE`) for text nodes. + ::: -## Children and Content +## Children :::note Types of Children @@ -55,7 +57,7 @@ This is important because some properties return **only child elements**, wherea container.childNodes // [text, div, text] -// extra text nodes contain newline and space characters +// extra text nodes contain newline and space ``` Read more about [other types of nodes](https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType) and how [whitespace works in html](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace).