I have this function that iterates over all checkboxes in a table and checks them. I also made a counter that will count the number of rows checked. Interestingly, the counter always returns one higher than my expected value. The counter is initialized as 0, so I expect it to increment for every checkbox but something else seems to be going on. Anyone know why this is?
var counter=0;
$('#checkAll').click(function (event){
$(':checkbox').each(function(){
this.checked=true
counter+=1
});
});
Minimal reproducible example: https://codepen.io/enyu0510/pen/eYrEgJe