I have a table and I want to select the rows that satisfy my criteria and check their respective checkbox. Let's say I want to get the rows with date 2013-03-21
. How can I do this using JQuery?
<table>
<tr>
<td>
Record1
</td>
<td>
2013-03-21
</td>
<td>
<input type="checkbox"/>
</td>
</tr>
<tr>
<td>
Record2
</td>
<td>
2013-03-22
</td>
<td>
<input type="checkbox"/>
</td>
</tr>
<tr>
<td>
Record3
</td>
<td>
2013-03-21
</td>
<td>
<input type="checkbox"/>
</td>
</tr>
</table>
$("table tr").each(function () {
if ($(this).find("td:eq(1)").text().trim() == '2013-03-21') {
$(this).find("input[type=checkbox]").attr("checked", true);
}
});
DEMO
You can use filter(), You better assign some id to table and use that in selector and be sepecific
Live Demo
trs = $('td').filter(function(){
if($.trim($(this).text()) == '2013-03-21')
return $(this).parent();
});
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