As someone new to JS and jQuery, I'm working on a table with multiple columns that contain numbers, except for the last one which has text. My goal is to first add the "custom-sortable" class to all elements in the last column that equal the word "Camp", and then add the "custom-sortable" class to all elements in the entire table where the last column equals to "Camp". I've tried different approaches, but haven't had success. My latest idea is to use the index of elements in the last column that include the word "Camp". Any help or hints would be appreciated.
Edit: The table is a html, the class is just to change the background color of all elements equal to "Camp".
The following code works in terms of adding the class to the last column.
.custom-sortable .rank-list-item.rank-list-item-Camp {
background-color: grey;
}
$(document).ready(function() {
var targetIndex = -1;
$('.custom-sortable .rank-list-item').each(function(index) {
if ($(this).text() === 'Camp') {
targetIndex = index;
$(this).addClass('custom-sortable rank-list-item-Camp');
}
});
if (targetIndex >= 0) {
$('.custom-sortable .rank-list-item').eq(targetIndex).addClass('custom-sortable');
}
});


<table>element's HTML? Both what you start with, and what you wish to end up with?