반응형

jQuery로 class나 id로 checkbox를 check시키는건 쉽다.
동적으로 생성된 checkbox 역시 쉽다.
가령 부모 checkbox를 check 할 경우 자식 checkbox도 check 시켜야 할 경우

아래 샘플처럼 부모에 적당한 attr로 값을 주고 자식에겐 해당 attr의 class로 설정해준다면 부모 check시 자식도 check가 가능하다.

$("." 이후 + 로 부모의 attr값을 연결시켜주고 prop checked하면 끝난다.

$("." + $(this).attr("CODE")).prop("checked", true);

<input type="checkbox" name="parent" CODE="GROUP_1">
<input type="checkbox" name="child" class="GROUP_1">
<input type="checkbox" name="child" class="GROUP_1">

반응형
Posted by Hippalus
,