I need help writing a Javascript function that will loop through rows in a table and only change the background color of cells in "column2" if they are empty. My current code is not working as expected, as it colors all rows instead of just those with empty cells in "column2".
JS:
// loops through rows
for (var i = 0; rows; rows = tbody.rows[i]; i++) {
//loops through cells
for (var j = 1; col; col = rows.cells[j]; j++) {
//gets cells of current row
cells = rows[i].getElementsByTagName('td');
//gets cells of col 1
ocells = rows.cells[j].getElementByTagName('td');
while (rows.cells[j] === null) {
//condition here>>
}
}
}
HTML:
<div id="table">
<table name="tbody" id="tbody1">
<tr>
<td>col1 Val1</td>
<td>col2 Val2</td>
</tr>
<tr>
<td>col1 Val3</td>
<td>col2 Val4</td>
</tr>
</table>
</div>
If you can offer any assistance, I would greatly appreciate it!