Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think there's a bit of logic issue here.</p> <p>Say you have the parent, a child and a child's child, per your requirement, when you click on an unchecked child, the current element is checked and the child element of this as well as the parent of this is checked as well, but the sibling of this is not checked right?</p> <p>What happens when you click on the parent? None of the check box is checked? So if I decided to check all the check box, but I already have a child check box check, that means I will have to check the parent check box to un-check everything and then click on it again to check all the check boxes?</p> <p>This is not a very good user experiences. Anyway, I think the best thing to do is separate the function click events out into three different listeners instead of trying to do it in one function. With that in mind, I didn't write out the use case when you have everything checked and you un-check one of the child, then the parent check box should still be checked. You'll have to keep expanding these.</p> <pre><code>&lt;ul class="level-one"&gt; &lt;li class="level-one-closed"&gt; &lt;span class="level-one-folder"&gt; &lt;input type="checkbox" class="userPermissionCheckBox-level-one" /&gt; Parent &lt;/span&gt; &lt;ul class="level-two"&gt; &lt;li class="level-two-closed"&gt; &lt;span class="level-two-folder"&gt; &lt;input type="checkbox" class="userPermissionCheckBox-level-two" /&gt; Child &lt;/span&gt; &lt;ul class="level-three"&gt; &lt;li&gt; &lt;span class="level-three-folder"&gt; &lt;input type="checkbox" class="userPermissionCheckBox-level-three" /&gt; Child's Child &lt;/span&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="level-two-closed"&gt; &lt;span class="level-two-folder"&gt; &lt;input type="checkbox" class="userPermissionCheckBox-level-two" /&gt; Child &lt;/span&gt; &lt;ul class="level-three"&gt; &lt;li&gt; &lt;span class="level-three-folder"&gt; &lt;input type="checkbox" class="userPermissionCheckBox-level-three" /&gt; Child's Child &lt;/span&gt; &lt;/li&gt; &lt;li&gt; &lt;span class="level-three-folder"&gt; &lt;input type="checkbox" class="userPermissionCheckBox-level-three" /&gt; Child's Child &lt;/span&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; var $levelOneCheck = $('.userPermissionCheckBox-level-one'); var $levelTwoCheck = $('.userPermissionCheckBox-level-two'); var $levelThreeCheck = $('.userPermissionCheckBox-level-three'); $levelOneCheck.click(function() { var $isChecked = $(this).attr('isChecked'); if ($isChecked === 'true') { $(this).attr('isChecked', 'false'); $levelTwoCheck.prop('checked', false).attr('isChecked', 'false'); $levelThreeCheck.prop('checked', false).attr('isChecked', 'false'); } else { $(this).attr('isChecked', 'true'); $levelTwoCheck.prop('checked', true).attr('isChecked', 'true'); $levelThreeCheck.prop('checked', true).attr('isChecked', 'true'); } }); $levelTwoCheck.click(function() { var $isCheckedLevelTwo = $(this).attr('isChecked'); if ($isCheckedLevelTwo === 'true') { $(this).attr('isChecked', 'false'); $(this).closest('.level-one-closed').find('.level-one-folder .userPermissionCheckBox-level-one').prop('checked', false).attr('isChecked', 'false'); $(this).closest('.level-two-closed').find('.level-three-folder .userPermissionCheckBox-level-three').prop('checked', false).attr('isChecked', 'false'); } else { $(this).attr('isChecked', 'true'); $(this).closest('.level-one-closed').find('.level-one-folder .userPermissionCheckBox-level-one').prop('checked', true).attr('isChecked', 'true'); $(this).closest('.level-two-closed').find('.level-three-folder .userPermissionCheckBox-level-three').prop('checked', true).attr('isChecked', 'true'); } }); $levelThreeCheck.click(function() { var $isCheckedLevelTwo = $(this).attr('isChecked'); if ($isCheckedLevelTwo === 'true') { $(this).attr('isChecked', 'false'); $(this).closest('.level-one-closed').find('.level-one-folder .userPermissionCheckBox-level-one').prop('checked', false).attr('isChecked', 'false'); $(this).closest('.level-two-closed').find('.level-two-folder .userPermissionCheckBox-level-two').prop('checked', false).attr('isChecked', 'false'); } else { $(this).attr('isChecked', 'true'); $(this).closest('.level-one-closed').find('.level-one-folder .userPermissionCheckBox-level-one').prop('checked', true).attr('isChecked', 'true'); $(this).closest('.level-two-closed').find('.level-two-folder .userPermissionCheckBox-level-two').prop('checked', true).attr('isChecked', 'true'); } }); </code></pre> <p><a href="http://jsfiddle.net/xzigraz/BTXNk/3/" rel="nofollow">http://jsfiddle.net/xzigraz/BTXNk/3/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload