Javascript get child element text

Get the children of each DOM element within a set of DOM elements.


.children(selector, options)


Correct Usage

cy.get('nav').children() // Yield children of nav

Incorrect Usage

cy.children() // Errors, cannot be chained off 'cy'
cy.clock().children() // Errors, 'clock' does not yield DOM elements


selector (String selector)

A selector used to filter matching DOM elements.

options (Object)

Pass in an options object to change the default behavior of .children().

log true Displays the command in the Command log
timeout defaultCommandTimeout Time to wait for .children() to resolve before timing out


  • .children() yields the new DOM element(s) it found.


No Args

Get the children of the .secondary-nav

    <ul class="secondary-nav">
      <li class="services-1">Web Design</li>
      <li class="services-2">Logo Design</li>
      <li class="services-3">
        Print Design
        <ul class="tertiary-nav">
          <li>Business Cards</li>

// yields [
//  <li class="services-1">Web Design</li>,
//  <li class="services-2">Logo Design</li>,
//  <li class="services-3">Print Design</li>
// ]


Get the children with class active

    <li class="active">Unit Testing</li>
    <li>Integration Testing</li>

// yields [
//  <li class="active">Unit Testing</li>
// ]



  • .children() requires being chained off a command that yields DOM element(s).


  • .children() will automatically retry until the element(s) exist in the DOM
  • .children() will automatically retry until all chained assertions have passed


  • .children() can time out waiting for the element(s) to exist in the DOM .
  • .children() can time out waiting for assertions you've added to pass.

Command Log

Assert that there should be 8 children elements in a nav

cy.get('.left-nav>.nav').children().should('have.length', 8)

The commands above will display in the Command Log as:

Javascript get child element text

When clicking on the children command within the command log, the console outputs the following:

Javascript get child element text

See also

  • .next()
  • .parent()
  • .parents()
  • .siblings()

How do you get an element of a child?

To get the first child element of a specified element, you use the firstChild property of the element:.
let firstChild = parentElement.firstChild; ... .
let content = document.getElementById('menu'); let firstChild = content.firstChild.nodeName; console.log(firstChild); ... .

Which Javascript function is used to select the child tag from the parent element?

jQuery children() function. jQuery children() method is used to get the direct children of the selected HTML element. You can use children() method to traverse through the child elements of the selected parent element.

Which property maintains the Childelements of an element?

The children property returns a collection of an element's child elements.

What is childNode?

The childNodes property is a property of Node in Javascript and is used to return a Nodelist of child nodes. Nodelist items are objects, not strings and they can be accessed using index numbers. The first childNode starts at index 0. Syntax.