iTechMedium Uncategorized How I chenged checkbox bg color on when it is checked?

How I chenged checkbox bg color on when it is checked?

Your are not setting the color on the label but on the checkbox. jQuery makes it easy for you to select / traverse DOM elements (and also helps clean-up a lot of unnecessary IDs), see this fiddle :

$('input[type=checkbox]').change(function(){
if($(this).prop('checked')){
$
(this).parent().css('backgroundColor', '#bff0a1');
}else{
$
(this).parent().css('backgroundColor', '#eee');
}
});
Live Example

Leave a Reply

Your email address will not be published. Required fields are marked *