The ParentNode property children is a read-only property that returns a live HTMLCollection which contains all of the child elements of the node upon which it was called.
Syntax
var children = node.children;
Value
A HTMLCollection which is a live, ordered collection of the DOM elements which are children of node. You can access the individual child nodes in the collection by using either the item() method on the collection, or by using JavaScript array-style notation.
If the node has no element children, then children is an empty list with a length of 0.
Example
var foo = document.getElementById('foo');
for (var i = 0; i < foo.children.length; i++) {
console.log(foo.children[i].tagName);
}
Polyfill
// Overwrites native 'children' prototype.
// Adds Document & DocumentFragment support for IE9 & Safari.
// Returns array instead of HTMLCollection.
;(function(constructor) {
if (constructor &&
constructor.prototype &&
constructor.prototype.children == null) {
Object.defineProperty(constructor.prototype, 'children', {
get: function() {
var i = 0, node, nodes = this.childNodes, children = [];
while (node = nodes[i++]) {
if (node.nodeType === 1) {
children.push(node);
}
}
return children;
}
});
}
})(window.Node || window.Element);
Specification
| Specification | Status | Comment |
|---|---|---|
| DOM The definition of 'ParentNode.children' in that specification. |
Living Standard | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Basic support | Chrome Full support 1 | Edge Full support Yes | Firefox Full support 3.5 | IE
Full support
9
| Opera Full support 10 | Safari Full support 4 | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android Full support 4 | Opera Android ? | Safari iOS Full support 10 | Samsung Internet Android Full support Yes |
Support on Document and DocumentFragment | Chrome Full support 29 | Edge ? | Firefox Full support 25 | IE No support No | Opera Full support 16 | Safari No support No | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile ? | Firefox Android ? | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support Yes |
Support on SVGElement | Chrome Full support Yes | Edge No support No | Firefox Full support Yes | IE No support No | Opera ? | Safari No support No | WebView Android ? | Chrome Android ? | Edge Mobile ? | Firefox Android ? | Opera Android ? | Safari iOS ? | Samsung Internet Android ? |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- See implementation notes.
- See implementation notes.
See also
- The
ParentNodeandChildNodeinterfaces.
Document Tags and Contributors
Tags:
Contributors to this page:
ExE-Boss,
Sheppy,
Pbb,
jackblackevo,
Delapouite,
idontusenumbers,
k-gun,
jonkee,
vedmack,
Robg1,
fscholz,
Prome,
ziyunfei,
danburzo,
Kartik_Chadha,
teoli,
Krinkle,
Dan-Dascalescu,
fryn,
Philip Chee,
paul.irish,
janmoesen
Last updated by:
ExE-Boss,