1,$('input[id^="checkbox"]').click(function()
what’s the id^="checkbox" meaning?
2,
var checkall = $('#checkall');
var boxes = $('input[type="checkbox"]').not(checkall);
checkall.click(function () {
boxes.attr('checked', this.checked);
});
boxes.change(function() {
checkall[0].checked = this.checked && boxes.filter(':checked').length === boxes.length;
});
a, var boxes = $('input[type="checkbox"]').not(checkall);
does this line mean “give all type=checkbox input to boxes expect the id=checkall"
what’s these lines meaning? checkall[0].checked = this.checked && boxes.filter(':checked').length === boxes.length; and could i change this boxes.attr('checked', this.checked); to boxes.attr('checked', checked); thank you
all
inputelements that have id starting with letters “checkbox” like id=checkbox, id=checkbox1, id=checkboxABC etcvar boxes = $('input[type="checkbox"]').not(checkall);means get all input elements of type checkbox except the one with id=checkall
checkall[0].checked = this.checked && boxes.filter(':checked').length === boxes.length;set $(‘#checkall’)’s checked property to true if all checkboxes in the
boxesis checked. This is done by checking if the total number of checked checkboxes is equal to total number of checkboxes. The first partthis.checkedis not required but it doesn’t hurt. If current element if unchecked this first part will prevent the second part from executing and will set the status to false which is what you want.No, you can’t change
boxes.attr('checked', this.checked)toboxes.attr('checked', checked). You could’ve tried that yourself.if anyone is wondering how I answered these, I was helping OP solve this question yesterday and I know what OP was asking.