This script is designed to check each checkbox within a dropdown menu. If all checkboxes are checked, it will advance to the next dropdown. If it's the last dropdown, it will simply close itself.
const dropdowns = document.querySelectorAll(".dropdown");
dropdowns.forEach((e, i) => {
const h = e.querySelector(".info");
h.addEventListener("click", () => {
dropdowns.forEach((ee, ii) => {
const c = ee.querySelector(".content");
if (ii != i) c.style.display = "none";
else {
if (c.style.display == "none" || c.style.display == "") c.style.display = "flex";
else c.style.display = "none";
}
});
});
const c = e.querySelector(".content");
const checks = c.querySelectorAll("input[type='checkbox']");
checks.forEach((e) => {
e.addEventListener("change", () => {
const cs = Array.from(c.querySelectorAll("input[type='checkbox']")).map((e) => e.checked);
if (cs.indexOf(false) == -1 && i < dropdowns.length - 1) {
dropdowns.forEach((ee, ii) => {
const c = ee.querySelector(".content");
if (ii != i + 1) c.style.display = "none";
else {
if (c.style.display == "none" || c.style.display == "") c.style.display = "flex";
else c.style.display = "none";
}
});
} else if (cs.indexOf(false) == -1) {
c.style.display = "none";
}
});
});
});
.dropdown {
background-color: green;
}
.dropdown > .info {
background-color: lightgray;
border-bottom: 1px solid gray;
display: flex;
flex-direction: column;
padding: 10px;
cursor: pointer;
}
.dropdown > .content {
background-color: grey;
display: flex;
flex-direction: column;
padding: 10px;
display: none;
}
h2,
p {
margin: 0;
padding: 0;
}
<div class="dropdown">
<div class="info">
<h2>header</h2>
<p>information</p>
</div>
<div class="content">
<p><input type="checkbox" name="" id="" /> Lesson 1</p>
<p><input type="checkbox" name="" id="" /> Lesson 2</p>
<p><input type="checkbox" name="" id="" /> Lesson 3</p>
</div>
</div>
<div class="dropdown">
<div class="info">
<h2>header</h2>
<p>information</p>
</div>
<div class="content">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia, optio in? Consequuntur voluptatibus
repellat neque, aliquid maiores quisquam. Laborum ut minima id accusamus exercitationem, in obcaecati alias
ducimus et ipsum.
</p>
</div>
</div>
<div class="dropdown">
<div class="info">
<h2>header</h2>
<p>information</p>
</div>
<div class="content">
<p><input type="checkbox" name="" id="" /> Lesson 1</p>
<p><input type="checkbox" name="" id="" /> Lesson 2</p>
<p><input type="checkbox" name="" id="" /> Lesson 3</p>
</div>
</div>
<div class="dropdown">
<div class="info">
<h2>header</h2>
<p>information</p>
</div>
<div class="content">
<p><input type="checkbox" name="" id="" /> Lesson 1</p>
<p><input type="checkbox" name="" id="" /> Lesson 2</p>
<p><input type="checkbox" name="" id="" /> Lesson 3</p>
</div>
</div>
<div class="dropdown">
<div class="info">
<h2>header</h2>
<p>information</p>
</div>
<div class="content">
<p><input type="checkbox" name="" id="" /> Lesson 1</p>
<p><input type="checkbox" name="" id="" /> Lesson 2</p>
<p><input type="checkbox" name="" id="" /> Lesson 3</p>
</div>