ParentNode.children

« DOM Reference « ParentNode

The ParentNode.children read-only property returns a live HTMLCollection of child elements of the given object.

The items in the returned collection are objects and not strings. To get data from those node objects, you must use their properties (e.g. elementNodeReference.children[1].nodeName to get the name, etc.).

Syntax

var elList = elementNodeReference.children; 

elList is an ordered collection of element objects that are children of the current element. If the element has no children, then elList contains no elements.

The elList is a variable storing the node list of children. Such list is of type HTMLCollection. The children attribute is read-only.

Example

// pEl is an object reference to a <p> element
// So, first we check if the object is not empty, if the object has child elements
if (pEl.children.length) {
    var children = pEl.children;
    for (var i = 0; i < children.length; i++) {
        // Do something with each child element as children[i]
        // NOTE: List is live, Adding or removing children will change the list
    }
}

Specification

Specification Status Comment
DOM Living Standard Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (on Element) 1.0 3.5 (1.9.1) 9.0 [1] 10.0 4.0
Support on Document and DocumentFragment 29.0 25.0 (25.0) Not supported 16.0 Not supported
Support on SVGElement (Yes) (Yes) Not supported ? Not supported
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (on Element) (Yes) 1.0 (1.9.1) (Yes) (Yes) (Yes)
Support on Document and DocumentFragment (Yes) 25.0 (25.0) Not supported 16.0 Not supported

[1] Internet Explorer 6, 7 and 8 supported it, but erroneously includes Comment nodes.

See also

Document Tags and Contributors

Last updated by: danburzo,