본문 바로가기
JavaScript

[jQuery] 상위 체크박스 선택해제 시 하위 체크박스 disabled

by palbokdev 2021. 5. 18.
$('#parent-checkbox-id').change(function () {
  $('.child-checkbox-class').prop('disabled', !this.checked);
}).trigger('change');

상위 체크박스 선택 결과에 따라 하위 체크박스를 disable, enable 시킨다.

최초 로드 시 이미 체크되어있는 경우를 위해서 trigger를 사용한다.