I have a checkbox tree generated with php sql and the structure looks like this:
<input class="level_" name="1" type="checkbox" /> Parent element
<input class="level_z" name="153" type="checkbox" /> Child element
<input class="level_z" name="481" type="checkbox" /> Child element
<br/>
<input class="level_" name="5" type="checkbox" /> Parent element
<input class="level_zz" id="845" type="checkbox" /> Child element
<input class="level_zz" id="5613" type="checkbox" /> Child element
<input class="level_" name="2" type="checkbox" /> Parent element
<input class="level_z" name="154" type="checkbox" /> Child element
<input class="level_z" name="482" type="checkbox" /> Child element
<br/>
<input class="level_" name="8" type="checkbox" /> Parent element
<input class="level_zz" id="659" type="checkbox" /> Child element
<input class="level_zz" id="3643" type="checkbox" /> Child element
I want the child elements to be selected when I select the parent but since they all parent and child levels have the same id I can't treat them as individual groups. I have a jquery that manages to select all level_zz children after parent until next parent but that's not enough:
$('.level_').change(function() { $(".level_").nextUntil(".level_zz").attr('checked', $(this).attr('checked')); });
I don't know how to do it without unique parent identification and I can't change how the checkboxes are generated either.
I'd like the code would be:
"if certain parent (no unique class but unique name) is selected select all it's children too."
Aucun commentaire:
Enregistrer un commentaire