Reputation: 9392
I have an aspx page which renders as below.
<div id="div1">
<tr>
<td>SomeTxt</td>
<td><input checked="checked" class="check-box" disabled="disabled" type="checkbox" /></td>
<td>text2</td>
</tr>
</div>
Iam trying to read checkbox checked property from javascript :
var status = $('#div1 tbody tr:eq(' + tr.rowIndex + ') td:eq(1)').checked;
But I am getting undefined.
Upvotes: 0
Views: 240
Reputation: 6736
Something like this
var status = $("input[type='checkbox']:checked").val();
alert(status);
Upvotes: 0
Reputation: 32591
use is(':checked')
var status = $('#div1 input[type="checkbox"]').is(':checked');
Upvotes: 3
Reputation: 2653
td:eq(1) will return td and not the input element
var status = $('#div1 tbody tr:eq(' + tr.rowIndex + ') td:eq(1)').find("input").get(0).checked;
Regards,
Upvotes: 0
Reputation: 951
you can use:
$("#yourID").is(":checked")
Make sure give an ID to your checkbox, not taking it <tr>
Upvotes: 0
Reputation: 11751
A TD will not have the checked attribute, you must select the input element.
Upvotes: 0