children property

The children property stores a pseudo-array of child elements. All tags that are directly located inside a block are considered child elements.

Syntax

element.children;

Example

Let's loop through all the element's children and display their content:

<div id="parent"> <p>1</p> <p>2</p> <p>3</p> <p>4</p> <p>5</p> </div> let parent = document.querySelector('#parent'); let elems = parent.children; for (let elem of elems) { console.log(elem.textContent); }

See also

  • the childNodes property
    containing a pseudo-array of nodes
enru