I’m trying to set the class attribute of all the cells within a given row in a table. Here is what I’ve attempted but while I don’t get an exception, it doesn’t work either.
Here is a sample of the current html for the rows/cells is as follows.
<tr id="rowid-1234">
<td class="tblistred">20-400 Silver Metal Closure</td>
<td class="tblistred">Tecno, LLC</td>
<td class="tblistred">Closure</td>
<td class="tblistred">New Item</td>
</tr>
Here is my script:
var rowId = "#rowid-" + response.id;
$(rowId).each(function (index) {
$(this).children('td').addClass('tblist');
});
UPDATE
OK, I changed it to this, but it still isn’t setting the class.
alert($(rowId).find("td:first-child").text());
$(rowId).children('td').addClass('tblist');
I added the alert to ensure that I have the correct row, and it confirms that I do.
SOLUTION
I had to Remove the class that was already there
$(rowId + ' td').removeClass('tblistred').addClass('tblist');
I had to remove the existing class from the td before adding the class.
I found the answer here.
Here is what I ended up with.