Problems:Wanting to check all checkboxes when the checkbox w/id=checkall is checked.Wanting to uncheck the checkall box when any other checkbox is unchecked.Solution:$(document).ready(function () {$('#checkall').on('click', function () {if ($(this).is(':checked')) {    $('input[type=checkbox]').each(function () {        console.log(this);        this.checked = true;    });} else {    $('input[type=checkbox]').each(function () {        this.checked = false;    });}// Uncheck Checkall if any other checkbox is uncheckedif ($('#checkall').is(':checked')) {    $('input[type=checkbox]:not(#checkall)').click(function () {        console.log(this);        $('#checkall').attr('checked', false);    });}});});I'm new with jQuery and I'm not sure if what I've written is really and truly production value code, but it is operational. It's not a matter of life and death, it's really just a personal project I'm working on that will likely be used by myself and some friends only. I am in the game to learn, though, and if the code can be improved upon please point me in the right direction to read about it more in depth. I've only been able to find bits and pieces on this topic.
Checking all checkboxes
javascript;beginner;jquery;html;form
I've written my changes in the code with comments, it explains it easier :) Most of the changes are good to knows and you dont need the each() if you want them all to do the same.$(document).ready(function () {    // We use the checkboxes multiple times on a page, save the reference    // This will save DOM lookups, thus smoother performance (though very little in this case)    var $allCheckBoxes = $('input[type=checkbox]').not('#checkall'); // prefix with $ to indicate jQuery object (this is a preference, not a must)    // We use it multiple times, save the reference    var $checkAllTrigger = $('#checkall');     // We only need to calc this once, not needed every click, so save it in a var    var allCheckBoxesLength = $allCheckBoxes; // this gets set once, and that's exactly enough    $checkAllTrigger.on('click', function () {        // Use this.checked, this  is the clicked element, .checked is true/false if it's checked or not        $allCheckBoxes.prop('checked', this.checked);     })    // as per Paul's comment, blur the element to remove.    // We chain the blur() to the on(), on() returns the object, you can think $(this)     // gets returned, which you then blur.     .blur();    // Uncheck Checkall if any other checkbox is unchecked    // We do this by comparing the total amount of checkboxes vs the checked ones.    // If e.g. 10 out of 10 are checked, they're all checked, check this on    $allCheckBoxes.on('change', function(){        $checkAllTrigger.prop('checked', allCheckBoxesLength == $allCheckBoxes.filter(:checked).length);    });});