Currently - I am using the “checkbox hack” to show/hide some divs on a page. The problem is, the page will be dynamic so the number of Divs will change. For instance, it may be like this:
<label for="toggle-1"> Label here </label>
<input type="checkbox" id="toggle-1">
<div class="description-1"><h6>Description</h6> Some words here. </div>
Or it may be like this:
<label for="toggle-1"> Label here </label>
<input type="checkbox" id="toggle-1">
<div class="description-1"><h6>Description</h6> Some words here. </div>
<label for="toggle-2"> Label here </label>
<input type="checkbox" id="toggle-2">
<div class="description-2"><h6>Description</h6> Some words here. </div>
There may also be 3, or 4 or more… you get the picture.
My CSS for showing and hiding the description Divs separately is currently setup like this:
Two things, firstly what you have uses the General Sibling selector ~ which does not descriminate, so when you check the first box, you see both descriptions. Better to use the Adjacent Sibling + selector instead for this.
To the actual question. Why such specific classes for each item?
Using a generic class will apply the rules to any number of objects.