Thursday, December 29, 2011

Ubah Kondisi Elemen Induk Jika CheckBox Dicentang (Checked)

jQuery Snippets

jQuery

$('div.area').find('input:checkbox').change(function() {
    if ($(this).is(':checked')) {
        $(this).parent().addClass('active');
    } else {
        $(this).parent().removeClass('active');
    }
});

CSS

.area {
  padding:10px;
  border:1px solid #ccc;
}

.active {background-color:yellow}

Lihat Demo

Thank’s Mottie :D

Labels: , ,

0 Comments:

Post a Comment

<< Home