Currently revamping my portfolio website and could use a hand with some jQuery code. Hoping to make a parent class react to a checkbox within it. Specifically looking to change the background color to #000
when the checkbox is checked.
Struggling to figure out which line of code to incorporate in order for my class to respond to the checkbox. Tried looking up tutorials online, but haven't made much progress. It's probably just a minor tweak that I'm missing, so any assistance would be greatly appreciated.
$("input[type='checkbox']").change(function() {
if ($(this).is(":checked")) {
$(this).parent().css('background-color', '#000');
} else {
$(this).parent().css('background-color', '#ccc');
}
});
.product {
background-color: #ccc;
/* needs to change to #000 when active */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div class="product">
<input class="check" type="checkbox" name="logo"> Logo
</div>