A live NodeList
containing the children of the node.
Note: Several calls to childNodes
return the same NodeList
.
// Note that para is an object reference to a <p> element
// First check that the element has child nodes
if (para.hasChildNodes()) {
let children = para.childNodes;
for (const node of children) {
// Do something with each child as children[i]
// NOTE: List is live! Adding or removing children will change the list's `length`
}
}
Remove all children from a node
// This is one way to remove all children from a node
// box is an object reference to an element
while (box.firstChild) {
// The list is LIVE so it will re-index each call
box.removeChild(box.firstChild);
}
Specifications Browser compatibility
Loadingâ¦
See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.5