$(document).ready(function () { checkboxAccordionInit(); }); function checkboxAccordionInit() { $(".Checkbox-parent input").on('click', function () { var _parent = $(this); var nextli = $(this).parent().next().children().children(); if (_parent.prop('checked')) { console.log('Checkbox-parent checked'); nextli.each(function () { $(this).children().prop('checked', true); }); } else { console.log('Checkbox-parent un checked'); nextli.each(function () { $(this).children().prop('checked', false); }); } }); $(".Checkbox-child input").on('click', function () { var ths = $(this); var parentinput = ths.closest('div').prev().children(); var sibblingsli = ths.closest('ul').find('li'); if (ths.prop('checked')) { console.log('Checkbox-child checked'); parentinput.prop('checked', true); } else { console.log('Checkbox-child unchecked'); var status = true; sibblingsli.each(function () { console.log('sibb'); if ($(this).children().prop('checked')) status = false; }); if (status) parentinput.prop('checked', false); } }); // show hide accordion var acc = document.getElementsByClassName("Accordion"); var i; for (i = 0; i < acc.length; i++) { acc[i].addEventListener("click", function () { this.classList.toggle("Accordion--active"); var panel = this.nextElementSibling; if (panel.style.maxHeight) { panel.style.maxHeight = null; } else { panel.style.maxHeight = panel.scrollHeight + "px"; } }); } } /* function test() { $('.Checkbox-parent input').on('click', function () { var $chk = $(this), $li = $chk.closest('div'), $ul, $parent; if ($li.has('ul')) { $li.find(':checkbox').not(this).prop('checked', this.checked) } do { $ul = $li.parent(); $parent = $ul.siblings(':checkbox'); if ($chk.is(':checked')) { $parent.prop('checked', $ul.has(':checkbox:not(:checked)').length == 0) } else { $parent.prop('checked', false) } $chk = $parent; $li = $chk.closest('div'); } while ($ul.is(':not(.someclass)')); }); } */