On my webpage, I am facing an issue with checkboxes. No matter which checkbox I click on, only the first one is getting checked. I can't figure out what the problem is. Initially, the checkboxes weren't showing as checked, but now only the first one stays selected. There is a button that selects all the checkboxes and that works fine. The problem arises when users try to individually select checkboxes.
Code
.checkbox {
margin: 3px auto;
width: 25px;
position: relative;
}
.checklabel {
cursor: pointer;
position: absolute;
width: 25px;
height: 25px;
top: 0;
left: 0;
background: #eee;
border:1px solid #ddd;
}
.checkbox .checklabel:after {
opacity: 0.2;
content: '';
position: absolute;
width: 9px;
height: 5px;
background: transparent;
top: 6px;
left: 7px;
border: 3px solid #333;
border-top: none;
border-right: none;
transform: rotate(-45deg);
}
.checklabel:hover::after {
opacity: .5;
}
.checkbox input[type=checkbox]:checked + .checklabel:after {
opacity: 1;
}
<td><div class="checkbox"><input class="check" id="check" type="checkbox"><label class="checklabel" for="check"></label></div></td>
<td><div class="checkbox"><input class="check" id="check" type="checkbox"><label class="checklabel" for="check"></label></div></td>