From e7d6796921567b69ac5119503f924410663be742 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Wed, 4 Nov 2020 18:56:31 +0530 Subject: [PATCH] element-properties - Add hasChildNodes and childElementCount --- docs/element-properties.mdx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/element-properties.mdx b/docs/element-properties.mdx index b4cdd5e..5cc636b 100644 --- a/docs/element-properties.mdx +++ b/docs/element-properties.mdx @@ -99,11 +99,21 @@ for (let i = 0; i < children.length; i++) { ``` +:::note Counting number of child elements + +`Element.childElementCount : number` +It returns the **number of child elements** of the given element. + +This is equivalent to `ele.children.length` value. + +::: + + ### 3. childNodes -`Element.childNodes: NodeList` +`Node.childNodes: NodeList` This read-only property returns a live `NodeList` containing all the **child nodes** of the current element, including text nodes. If there are no child nodes, it returns a empty NodeList. @@ -127,6 +137,15 @@ childNodes // NodeList [text, span, text] }) ``` +:::note Is there any child node? + +`Node.hasChildNodes() : boolean` +This method returns a boolean value, indicating whether the given Node **has child nodes or not**. + +This is equivalent to checking `node.childNodes.length > 0`. + +::: + ### 4. firstChild + nextSibling