childNodes Property
Definition
The `childNodes` property returns a collection list of an element's child nodes.
Value
The `childNodes` property returns a `NodeList` object.
Usage
You can check if an element has child nodes using `element.hasChildNodes`. This method returns a boolean value indicating whether the element has child nodes.
For example:
```html const element = document.getElementById('myElement'); if (element.hasChildNodes()) { // The element has at least one child node. } ```You can also use the `childNodes` property to iterate over an element's child nodes. For example:
```html const element = document.getElementById('myElement'); for (let i = 0; i < element.childNodes.length; i++) { const childNode = element.childNodes[i]; // Do something with the child node. } ```Notes
- If you leave any white space or line feeds, the list will still have child nodes.
- The `childNodes` property is read-only.
Komentar