My html:
<div id="dvUser">
<table id="tblUser" >
<tbody>
<tr>
<td>
<input class="sfCheckBox" type="checkbox" title="view" checked="checked">
</td>
</tr>
<tr>
<td>
<input class="sfCheckBox" type="checkbox" title="edit">
</td>
</tr>
</tbody>
</table>
</div>
and Jquery:
$('#spnBtnSave').live("click", function() {
var checks = $( #dvUser tr:gt(0)').find('input.sfCheckbox:checked');
$.each(checks, function(index, item) {
if ($(this).attr("checked")) {
alert($(this).closest('table').attr('id'));
alert("test");
}
});
alert return blank.Unable to return table attribute id.What is my mistake.Thanks.
These are the things I did, and here is a working jsFiddle:
– The
$.eachloop, can be called on a set of objects, so you don’t have to make a separate array.– I fixed capitalization in
input.sfCheckBox:checked, previously it wasCheckboxand the html example uses the classCheckBox– I merged your selectors for the checkboxes to this
$( '#dvUser input.sfCheckBox:checked')– You only select checked inputs, so you don’t need to test if they are checked again in the
eachloop