So when I click the checkbox, the background colour changes. I want this function to work for all checkboxes, but it is currently only working for the first one.
function obtained() {
var obt = document.getElementsByClassName("obtained")[0];
var col = document.getElementsByClassName("entry")[0];
if (obt.checked == true) {
col.style.backgroundColor = "#2ab320";
} else {
col.style.backgroundColor = "#d3d5db";
}
}
<div class="entry">
<img class="class-name" src="image1.png">
<b>title1</b><br>content1
<input
type="checkbox"
class="obtained"
onclick="obtained()"
name="obtained"
>
</div><hr>
<div class="entry">
<img class="class-name" src="image2.png">
<b>title2</b><br>content2
<input
type="checkbox"
class="obtained"
onclick="obtained()"
name="obtained"
/>
</div><hr>
<div class="entry">
<img class="class-name" src="image3.png">
<b>title3</b><br>content3
<input
type="checkbox"
class="obtained"
onclick="obtained()"
name="obtained"
/>
</div><hr>