mardi 31 mai 2016

using jquery - when a checkbox with class .a is checked, check preceding box with class.b [duplicate]

This question already has an answer here:

When any checkbox with class .child-term is checked, I automatically need to check the preceding checkbox with class .parent-term.

I only want to check the preceding .parent-term class not all the checkboxes that have .parent-class. Same goes for the .child-term class. Any checkbox with .child-term only affects the .parent-term above.

If the .parent-term class was checked from a .sub-term checkbox the .parent-term can remain checked when all the associated .sub-term boxes are unchecked.

I have tried various solutions, but I can't figure it out.

I started a jsfiddle.

<ul class="cpt-terms-checkbox">
    <li class="parent-term church" id="category-church"><input id="church"
    name="church" type="checkbox" value="church">Church</li>

    <li><small>Sub Categories:</small></li>

    <li class="child-term elder" id="category-elder"><input id="elder"
    name="elder" type="checkbox" value="elder">Elder</li>
    <li class="child-term interim-pastor" id="category-interim-pastor">
    <input id="interim-pastor" name="interim-pastor" type="checkbox" value=
    "interim-pastor">Interim Pastor</li>

    <li class="parent-term law-firm" id="category-law-firm"><input id=
    "law-firm" name="law-firm" type="checkbox" value="law-firm">Law
    Firm</li>

    <li><small>Sub Categories:</small></li>

    <li class="child-term attorney" id="category-attorney"><input id=
    "attorney" name="attorney" type="checkbox" value=
    "attorney">Attorney</li>
    <li class="child-term attorney" id="category-attorney"><input id=
    "attorney" name="attorney" type="checkbox" value=
    "attorney">Paralegal</li>
</ul>




Aucun commentaire:

Enregistrer un commentaire