$( document ).ready(function() { $('button.Next[type="submit"]').on('click', function() { $cbx_group = $("input:checkbox[name='answer_code[]']"); if($cbx_group.is(":checked")) { $cbx_group.prop('required', false); } }); $('#clearAnswers').on('click', function() { const $inputs = $('#pollForm input:checked'); $inputs.prop('checked', false); $inputs.attr('checked', false); const $divs = $('#pollForm div.Checked'); $divs.removeClass('Checked'); }); $('input[type=checkbox]').on('change', function () { const parent = $(this).parent(); let limit = parent.data('max-answers'); if(!limit) { limit = 99; } if($('div.Checkbox.Checked').length > limit) { console.log('Ponad limit'); $(this).prop('checked', false); $(this).attr('checked', false); parent.removeClass('Checked'); } }); $('textarea').change(function(e) { this.value = this.value.trim(); }); });