I have table where each row starts with a "checkbox", I'd like to get all the TR that contains a checkbox and it is check.
Something like this:
$('#' + tableId + ' > tbody > tr:contains(td > input[type=checkbox]:checked').each(function (i, item) {
alert('delete ' + $(item).data('row-id'));
});
That code doesn't work, it gets stuck. Probably because the "contains" selector is only for text. How could I do it?
Regards.
You could just grab the checkboxes and then find their closest
tr
:Note, you're also missing
)
to close thecontains
.You don't need to
:contains
selector.If you want it to be anywhere inside the
<tr>
(even inside nested elements)If you want it directly inside of it
Use jQuery's has:
For better performance (see the jQuery API docs), use this:
Since the
has
query cannot be run throughquerySelectorAll()
, there's no need to use[type=checkbox]
.