You are on page 1of 8

12/18/2019 ParentNode.

children - Web APIs | MDN

Sign in

Search MDN

Technologies ▼

References & Guides ▼

Feedback ▼

ParentNode.children
English ▼

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
An 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

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children 1/8
12/18/2019 ParentNode.children - Web APIs | MDN

1 const foo = document.getElementById('foo');


2 for (let i = 0; i < foo.children.length; i++) {
3 console.log(foo.children[i].tagName);
4 }

Polyfill

1 // Overwrites native 'children' prototype.


2 // Adds Document & DocumentFragment support for IE9 & Safari.
3 // Returns array instead of HTMLCollection.
4 ;(function(constructor) {
5 if (constructor &&
6 constructor.prototype &&
7 constructor.prototype.children == null) {
8 Object.defineProperty(constructor.prototype, 'children', {
9 get: function() {
10 var i = 0, node, nodes = this.childNodes, children = [];
11 while (node = nodes[i++]) {
12 if (node.nodeType === 1) {
13 children.push(node);
14 }
15 }
16 return children;
17 }
18 });
19 }
20 })(window.Node || window.Element);

Specification
Specification Status Comment

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children 2/8
12/18/2019 ParentNode.children - Web APIs | MDN

DOM LS Living Standard Initial definition.


The definition of 'ParentNode.children' in that specification.

Browser compatibility
Update compatibility data on GitHub

children

Chrome 1

Edge Yes

Firefox 3.5

IE 9

Opera 10

Safari 4

WebView Android Yes

Chrome Android Yes

Firefox Android 4

Opera Android ?

Safari iOS 9

Samsung Internet Android Yes

Support on Document and DocumentFragment

Chrome 29

Edge 16

Firefox 25

IE No

Opera 16

Safari 9
https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children 3/8
12/18/2019 ParentNode.children - Web APIs | MDN

WebView Android Yes

Chrome Android Yes

Firefox Android ?

Opera Android ?

Safari iOS 9

Samsung Internet Android Yes

Support on SVGElement

Chrome Yes

Edge 16

Firefox Yes

IE No

Opera ?

Safari 9

WebView Android Yes

Chrome Android Yes

Firefox Android ?

Opera Android ?

Safari iOS 9

Samsung Internet Android ?

What are we missing?

Full support

No support

Compatibility unknown

Experimental. Expect behavior to change in the future.


https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children 4/8
12/18/2019 ParentNode.children - Web APIs | MDN

See implementation notes.

See also
The ParentNode and ChildNode interfaces.

Object types implementing this interface: Document , Element , and


DocumentFragment .

Node.childNodes

Last modified: Mar 23, 2019, by MDN contributors

Syntax
Example
Polyfill
Specification
Browser compatibility
See also

Related Topics
Document Object Model

ParentNode

▼ Properties

childElementCount

children

firstElementChild

lastElementChild

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children 5/8
12/18/2019 ParentNode.children - Web APIs | MDN

▼ Methods

append()

prepend()

querySelector()

querySelectorAll()

▼ Implemented by:

Document

DocumentFragment

Element

▼ Related pages for DOM

AbortController

AbortSignal

AbstractRange

Attr

ByteString

CDATASection

CSSPrimitiveValue

CSSValue

CSSValueList

CharacterData

ChildNode

Comment

CustomEvent

DOMConfiguration

DOMError

DOMErrorHandler

DOMException

DOMImplementation

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children 6/8
12/18/2019 ParentNode.children - Web APIs | MDN
DOMImplementationList

DOMImplementationRegistry

DOMImplementationSource

DOMLocator

DOMObject

DOMParser

DOMPoint

DOMPointInit

DOMPointReadOnly

DOMRect

DOMString

DOMTimeStamp

DOMTokenList

DOMUserData

Document

DocumentFragment

DocumentType

Element

ElementTraversal

Entity

EntityReference

Event

EventTarget

HTMLCollection

MutationObserver

Node

NodeFilter

NodeIterator

NodeList

NonDocumentTypeChildNode

ProcessingInstruction

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children 7/8
12/18/2019 ParentNode.children - Web APIs | MDN
PromiseResolver

Range

StaticRange

Text

TextDecoder

TextEncoder

TimeRanges

TreeWalker

TypeInfo

USVString

UserDataHandler

XMLDocument

Learn the best of web development


Get the latest and greatest from MDN delivered straight to your inbox.

you@example.com

Sign up now

https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children 8/8

You might also like