Created
October 24, 2017 20:48
-
-
Save jerronimo/3bcdd55334c2d2f056e497f691d7e7b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string} box | |
* @param {string} all | |
* @param {string} item | |
*/ | |
function checkboxList(box, all, item) { | |
//select all statuses | |
$(box).on('change', all, function(){ | |
$(item).prop('checked', $(this).prop('checked')); | |
}); | |
//".checkbox" change | |
$(box).on('change', item, function(){ | |
//uncheck "select all", if one of the listed checkbox item is unchecked | |
if(false == $(this).prop('checked')){ //if this item is unchecked | |
$(all).prop('checked', false); //change "select all" checked status to false | |
} | |
//check "select all" if all checkbox items are checked | |
if ($(item+':checked').length == $(item).length ){ | |
$(all).prop('checked', true); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment