Find Which Nth Child A Div is Within Another Div

Finding the solution to this will yield a solution to a higher level problem that I have

<div>
  <div class='childDiv'></div>
  <div class='childDiv'></div>
  <div class='childDiv'></div>
</div>

var childrenDivs = document.querySelectorAll('childDiv');

childrenDivs.forEach(function(value) {
  console.log('This is child number: ' + [insert code]);
});

I want it to output

This is child number: 1
This is child number: 2
This is child number: 3

I can’t figure out how to find the child position of value. Is this possible?

9 thoughts on “Find Which Nth Child A Div is Within Another Div”

Leave a Comment