This is keeping me busy for a couple of days. How do I detect the first or last <td>
within a <tr>
with classname "is" and then change this class to "isf" (first in row) or "is" (last in row), keeping the middle "is" classes as they are?
So far I've got this using jQuery but nothing happens:
$( document ).ready(function() {
if ($("td.is").prevAll("td.is") = null) {
$("td.is").toggleClass('is isf');
} else if ($("td.is").nextAll("td.is") = null) {
$("td.is").toggleClass('is isl');
}
});
Changing .prevAll()
to .prev()
does not do the trick for me. I've got multiple table rows with the "is" class on different cells. This is what the table row looks like:
<tr class="row-months">
<td class="cell-month cell-jan jan1"></td>
<td class="cell-month cell-jan jan2"></td>
<td class="cell-month cell-feb feb1"></td>
<td class="cell-month cell-feb feb2"></td>
<td class="cell-month cell-mar mar1"></td>
<td class="cell-month cell-mar mar2 is"></td> <!-- FIRST "is" class in row, change "is" to "isf" -->
<td class="cell-month cell-apr apr1 is"></td>
<td class="cell-month cell-apr apr2 is"></td>
<td class="cell-month cell-may may1 is"></td>
<td class="cell-month cell-may may2 is"></td>
<td class="cell-month cell-jun jun1 is"></td>
<td class="cell-month cell-jun jun2 is"></td>
<td class="cell-month cell-jul jul1 is"></td>
<td class="cell-month cell-jul jul2 is"></td>
<td class="cell-month cell-aug aug1 is"></td> <!-- LAST "is" class in row, change "is" to "isl" -->
<td class="cell-month cell-aug aug2"></td>
<td class="cell-month cell-sep sep1"></td>
<td class="cell-month cell-sep sep2"></td>
<td class="cell-month cell-oct oct1"></td>
<td class="cell-month cell-oct oct2"></td>
<td class="cell-month cell-nov nov1"></td>
<td class="cell-month cell-nov nov2"></td>
<td class="cell-month cell-dec dec1"></td>
<td class="cell-month cell-dec dec2"></td>
</tr>