Please help me with this issues.
i'm going to get the index number of checked checkbox array which reside in a html table, but each time i alert the each of checkbox's index inside .each() , its will return 0 for each loop.
but this code will work if i remove the table and all its tr and td (leave the two checbox alone)
my jquery code:
function notify() {
$("input[type = 'checkbox']:checked").each(function(){
alert($(this).index()); /*always return zero when the check[] inside a table or div */
});
}
function main() {
$("input[type = 'button']").click(notify);
}
$(document).ready(main);
my html code:
<table>
<tr><td>
<input type='checkbox' name='check[]' />
</td><td>
<input type='checkbox' name='check[]' />
</td> </tr>
</table>
<input type='button' name='button' value='ok'/>
.index()without arguments returns the position of the node among its own siblings. And in every<td>your checkboxes are the first (and the only) ones - so you're getting0See api.jquery.com/index