mirror of
https://github.com/bendtherules/UiQuestions.git
synced 2026-08-18 22:02:42 +00:00
element-properties - Add hasChildNodes and childElementCount
This commit is contained in:
@@ -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.
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
|
||||||
<MDN title="children" url="https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children" />
|
<MDN title="children" url="https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children" />
|
||||||
|
|
||||||
### 3. childNodes
|
### 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.
|
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`.
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
<MDN title="childNodes" url="https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes" />
|
<MDN title="childNodes" url="https://developer.mozilla.org/en-US/docs/Web/API/Node/childNodes" />
|
||||||
|
|
||||||
### 4. firstChild + nextSibling
|
### 4. firstChild + nextSibling
|
||||||
|
|||||||
Reference in New Issue
Block a user