I'm selecting all child divs of area_enInfantry and looping through to adjust the text of certain ones. cardArray is a global const and myId is defined within the parent function.
Uncaught TypeError: Cannot read properties of undefined (reading 'getAttribute')
var field = $(#area_en + cardArray[myId]['type']).find(div);
field.each(function(a, element) {
console.log(cC type: + cardArray[myId]['type'] + - index: + a + title: + element[a].attr('title'));
if (element[a].attr(title).indexOf(player) < 0) { // check this card isn't special player card
doStuff;
}
});
<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script>
<div id=area_enInfantry>
<div id=info_enInfantryScore class=info_Score>-1</div>
<div class=encardContainer title=barricade>-1</div>
<div class=encardContainer title=spy>2</div>
</div>
I read on this post that it may be because the contents of field/element may be DOM elements and that I should wrap them in $() so I did exactly that- changing both variables to $(element)[a].attr('title')
but now I get Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf') instead, seemingly moving the error to the next line.
What am I doing wrong here?