I am trying to add a class when a checkbox is checked.
My jquery:
$(\'input\').attr(\"checked\").change(function(){
$(\'div.menuitem\').addClass(\"me
$('.vfb-checkbox input:checkbox').change(function(){
if($(this).is(":checked")) {
$('.vfb-checkbox label').addClass("checked");
} else {
$('.vfb-checkbox label').removeClass("checked");
}
});
.vfb-checkbox{
width:180px;
height:130px;
background:url('http://i304.photobucket.com/albums/nn181/Amam_Dewan/2932337756_1845773ed4_q_d_zpsea5idhnt.jpg');
}
/* checkboxes */
.vfb-checkbox label {
cursor: pointer;
display: block;
position: relative;
width:100%;
height:100%;
}
.vfb-checkbox label:hover{
background:rgba(0,0,0,.7) url(http://i304.photobucket.com/albums/nn181/Amam_Dewan/selected_zpsvfoaira0.png)center center no-repeat;
}
.vfb-checkbox input[type=checkbox] {
display: none;
}
.checked{
background: rgba(0,0,0,.4) url('http://i304.photobucket.com/albums/nn181/Amam_Dewan/selected_zpsvfoaira0.png') center center no-repeat;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="vfb-checkbox">
<label id="checkbox" for="check1">
<input id="check1" type="checkbox" name="check" value="check1">
</label>
</div>
<div class="vfb-checkbox">
<label id="checkbox" for="check1">
<input id="check1" type="checkbox" name="check" value="check1">
</label>
</div>
I used jquery in checkbox. When I clicked on one element the other elements are effected. How can I fix this problem?