I came up with this function to add numbered classes to elements in row rows in my table:
$('tr td:contains(".")').each(function(i){ $(this).addClass("reportcellno-" + i); });
Basically, here I am looking for any table cell with a decimal point, and I want to interact through it in each row and add the class reportcellno-1
, reportcellno-2
It works very well, and I played with him all day. The only problem is that numbering continues and continues, rather than restricting it to a line.
My HTML output is from the above:
<tr> <td class="reportcellno-1">10.1</td> <td class="reportcellno-2">5.7</td> </tr> <tr> <td class="reportcellno-3">10.6</td> <td class="reportcellno-4">10.9</td> </tr>
While I'm really trying to get this:
<tr> <td class="reportcellno-1">10.1</td> <td class="reportcellno-2">5.7</td> </tr> <tr> <td class="reportcellno-1">10.6</td> <td class="reportcellno-2">10.9</td> </tr>
So essentially for each row of the table, I want to start numbering. I'm not even sure that this is possible.
source share