I'm just starting out with JavaScript although I have used a number of other languages previously. I'm finding the orientation pretty painful and I'd appreciate some guidance on how to access child elements within a forEach loop (or a jQuery .each loop). At this stage I don't really care whether the solution is JS or jQuery, I'm just trying to get something that works.
Say I have a node element that I have found using jQuery and I now have some processing to do on each row, which includes needing to find a child-element whose id contains an index related to the parent node in question:
$('.row').each((index, item) => {
var name = item.getElementById(`#name-${index}`);
});
It seems that it should be straightforward to select the element using getElementById, but this results in an 'item.getElementById is not a function' error.
I've also tried a jQuery approach:
var name = item.find('#name-0')
this gets an 'item.find is not a function' error.
I don't know if item should be in {} - it's not clear to me when the braces are needed and when they are not, but if I try it with the braces I still get a '.find is not a function' error.
Can someone point out what I'm doing wrong, or even better point me in the right direction of somewhere this is documented. All I can find is very simplistic examples.
Edited to include minimal HTML example: (and amended to fix missing div tags)
<div id="container" class="position-relative col-10>
<div id="row-0" class="row position-relative">
<div id="name-0" class="column col-4">User 1</div>
<div id="score-0" class="column col-2">20</div>
</div>
<div id="row-1" class="row position-relative">
<div id="name-1" class="column col-4">User 2</div>
<div id="score-1" class="column col-2">10</div>
</div>
<div id="row-2" class="row position-relative">
<div id="name-2" class="column col-4 ">User 3</div>
<div id="score-2" class="column col-2">5</div>
</div>
</div>