Hello!! In general, this situation has developed, there is a list of employees and there are departments. In each department of employees from 10 to 30, you select the department you have a list of employees, the whole thing works through ajax. Next to each employee is a checkbox. Set up the first option, everything works up to one moment, until you choose another department.
$(document).ready(function () { var UserSecurity = $('#UserSecurity').html(); var arr =[]; //Проверка checkbox $(function(){$('.CheckboxEmployees').click(function(){ if($(this).is(':checked')){ console.log("Нажата") var bufer = $(this).val(); arr.push(bufer); console.log(arr) } else{ console.log('отжата'); bufer = $(this).val(); arr.splice(arr.indexOf(bufer),1) console.log(arr); } }); }); If you remove an anonymous function, then nothing works at all, tell me what the problem is?