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

javascriptelement.children;

Example

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

html<div id="parent">
  <p>1</p>
  <p>2</p>
  <p>3</p>
  <p>4</p>
  <p>5</p>
</div>
javascriptlet 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