(Cross-posted from StackOverflow)
$(this).parents("tr").children("td").find('input[type=checkbox]:checked')
When you tick the
checkall
checkbox, it will be matched by this selector. It doesn't have an explicit value set, so
.val()
will return the string
"on"
.
Obviously, the string
"on"
cannot be converted to an integer, so your total will become
NaN
.
Exclude the
.checkall
checkbox from your selector, and your code will work.
$(this).parents('tr').find(':checkbox:checked').not(".checkall").each(...
Updated fiddle[
^]
NB: You should also pay attention to
the jQuery documentation[
^] -
$(document).ready(fn)
has been deprecated since v3. Use
$(fn)
instead.
Edit: Based on your updated Fiddle, you just need to trigger the
change
event of your checkbox after you've updated it from the
SelectAll
function:
table.find('td:nth-child(' + columnIndex + ') input').prop("checked", obj.checked).change();
Demo[
^]