So I'm trying to use jquery to detect when a checkbox has been checked and unchecked (by clicking the label I should add) to change a css attribute.
Here's an example of the code for the checkbox:
<div class="block" id="block_1">
<input type="checkbox" name="images" id="image_1" class="block_input" />
<label for="image_1" class="block_button" style="background-image:url(img/bnw/block_1bnw.png);">
<span>Label text</span></label>
</div>
and here is the jQuery I have so far that only half works:
$('.block_button').click(function(){
var imgId = $(this).parent().attr('id');
if ($(this).siblings('.block_input').checked == true) {
$(this).css("background-image", "url(img/color/" + imgId + ".png)");
} else {
$(this).css("background-image", "url(img/bnw/" + imgId + "bnw.png)");
}
});
The css changes correctly when you check the box initially, but once it's unchecked nothing changes. I've tried logging the result of the .checked method on click and it seems to stay true even when you uncheck. So how do I get the else statement to work once the user decides to uncheck the box?
Thanks!!