I have a table #mytable with a column
<table id="#mytable">
<tr><td class="name">John</td></tr>
<tr><td class="name">Paul</td></tr>
<tr><td class="name">Mary</td></tr>
</table>
I want to add a class to if the name is contained in an array. So I did the following :
jQuery.each($('#mytable .name'), function () {
var line = $(this).closest("tr");
var name = this.textContent;
if (['David','Paul','Melissa'].includes(name)) {
line.addClass("yes");
}
});
This works fine, the class .yes will be added to the 2nd line, the one containing Paul.
However, my problem is when trying to get the actual array. The values are contained in a repeater subfield. So i added a variable and tried to replace the array by my variable :
jQuery.each($('#mytable .name'), function () {
var line = $(this).closest("tr");
var name = this.textContent;
var repeaternames = $('#myrepeater .names .acf-input .select2-selection__rendered');
if (repeaternames.includes(name)) {
line.addClass("yes");
}
});
But this doesn't work. Is it a syntax issue, is it because my "repeaternames" variable is not an actual array ?
Or because I'm not getting the right values? As you can see, the repeater values that I'm trying to get are in a select2 select field, and maybe i'm not targeting the right elements.
Thank you in advance for your help !!