JavaScript childNodes Property Tutorial

In this section, we will learn what the Element childNodes property is and how to use it in JavaScript.

What is Element childNodes Property in JavaScript?

The JavaScript Element childNodes property is used to get the entire children of an element.

Basically, this property returns a reference to a collection that contains the entire child-elements of an element as its items.

So using this property, we can access to each child element and apply any sort of modifications if needed.

Note: other than the childNodes property, we have another property called `children` which will return the child elements of an element. The difference however is that the childNodes property returns the entire children of an element (including text nodes and comment nodes) while the children property only returns those children that are of type element-node.

Element childNodes Property Syntax:

element.childNodes;

Element childNodes Property Input Values

This property is read-only and so we can’t assign a value to it.

Element childNodes Property Return Value

The return value of this method is a reference to a collection called NodeList that contains the entire children of an element set as its items.

Example: JavaScript get child element

See the Pen JavaScript get child element by Omid Dehghan (@odchan1) on CodePen.

Leave a Reply