Reputation: 1
Is it possible to change red background of a div when checkbox is checked with jquery. Example fiddle
<div class="col-md-4 wizardBox">
<label for="img1">
<img src="http://beststore.bugs3.com/img/sample/portfolio-macbook.fw.png" />
<p>Culture</p>
<input type="checkbox" class="img1" id="img1" name="img1" value="" />
</label>
</div>
Upvotes: 0
Views: 49
Reputation: 1934
Hi it is good practice to cache the control in variable
//here we getting the control(div) in the variable
var $div=$('.wizardBox');
$('#img1').change(function() {
if($(this).is(":checked"))
$div.css('background-color','red');
else
$div.css('background-color','');
});
i have updated the JSFiddle for you click here to see
Upvotes: 0
Reputation: 15393
Try
$('#img1').click(function() {
if($(this).is(":checked"))
$(this).closest(".wizardBox").css('background-color','red');
});
Upvotes: 0
Reputation: 82231
You can use:
$('#img1').change(function() {
if($(this).is(":checked"))
$('.wizardBox').css('background-color','red');
else
$('.wizardBox').css('background-color','');
});
Upvotes: 1
Reputation: 9705
Yes...just listen to a change event on the checkbox, and change the background.
Upvotes: 0