jquery - Change background color of div when checkbox is clicked -
i have form several checkboxes, this:
<div><input type='checkbox' name='groupid' value='1'>1</div> <div><input type='checkbox' name='groupid' value='2'>2</div> <div><input type='checkbox' name='groupid' value='3'>3</div> what i'm trying when checkbox checked, change background color of div, , when it's unchecked, remove background color. how can using jquery?
thanks
jquery:
$("input[type='checkbox']").change(function(){ if($(this).is(":checked")){ $(this).parent().addclass("redbackground"); }else{ $(this).parent().removeclass("redbackground"); } }); css:
.redbackground{ background-color: red; } i'd recommend using add/remove class, opposed changing css of parent div directly.
Comments
Post a Comment