Solution to select all and get value value value of the iCheck plug-in

Keywords: JQuery Google

When we use the jQuery iCheck plug-in, we encounter a problem, that is, when we use the normal js select all function, it is invalid.


This is OK for the default checkbox box, but it will not work when the iCheck plug-in is used.

So how to solve it?

Finally, the solution is found in stackoverflow:

Here is the address:

//Select all to get the value
	var checkAll = $('input.all');
	var checkboxes = $('input.check');
	checkAll.on('ifChecked ifUnchecked', function(event) {
		if (event.type == 'ifChecked') {
		} else {
	checkboxes.on('ifChanged', function(event){
		if(checkboxes.filter(':checked').length == checkboxes.length) {
			checkAll.prop('checked', 'checked');
		} else {

After the problem of all selection is solved, a new problem is encountered. To get the value of the selected checkbox, use $(this).attr('checked '); if you can't get the value ~, the egg hurts.

Finally, after several Google searches, we find the inspiration in stack overflow to judge the Boolean value of checkbox, using $(this).is(':checked');

The final code solution is as follows:

	var url = $(this).attr('data-url');
	var str="";
	var ids="";
		if(true == $(this).is(':checked')){
	if(str.substr(str.length-1)== ','){
		ids = str.substr(0,str.length-1);


Posted by showman on Mon, 02 Dec 2019 05:49:54 -0800