I am using JQuery to iterate through all TRs in a table,
but not all rows have values in the first cell.
<TR>
<TD>3</TD>
<TD>2</TD>
<TD>1</TD>
</TR>
<TD></TD>
<TD>3</TD>
<TD>2</TD>
<TR>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD>3</TD>
</TR>
How can i target the first TD in each row that is not empty and not just the first child?
Thanks!
Here's a simpler, more elegant solution:
$('tr').find('td:not(:empty):first').css('background', 'red');
Fiddle: http://jsfiddle.net/dandv/JRcEf/
It just says in jQuery what you mean: "target the first td
in each tr
that is not empty".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With