Note that there are some explanatory texts on larger screens.

plurals
  1. POauto check parent checkbox
    primarykey
    data
    text
    <p>I have an AJAX request that pulls in a list of folders with a checkbox next to each list item. If I check the checkbox next to a parent folder, I have all of the children folders automatically check by doing this: </p> <pre><code>var checkChildCheckBoxes = function(){ var isAlreadyChecked = $(this).attr('isChecked'); if(isAlreadyChecked == 'true'){ $(this).parents(':eq(1)').find('.userPermissionCheckBox').each(function(){ $(this).prop('checked', false); }); $(this).attr('isChecked', 'false'); } else{ $(this).parents(':eq(1)').find('.userPermissionCheckBox').each(function(){ $(this).prop('checked', true); }); $(this).attr('isChecked', 'true'); } } </code></pre> <p>This works splendidly. What I'm trying to solve is if you DID NOT have the parent checkbox checked and you check a child checkbox, it will automatically check the parent.</p> <p>I tried with no success to do it like this: </p> <pre><code>if($(this).parent('ul').find('.userPermissionCheckBox:eq(0)').is('checked')){ } else{ $(this).parent('ul').find('.userPermissionCheckBox:eq(0)').prop('checked', true); } </code></pre> <p>I didn't want to load this question with code, so I made a fiddle displaying how the list is structured and the way I'm using it. Go here: <a href="http://jsfiddle.net/BTXNk/1/" rel="nofollow">http://jsfiddle.net/BTXNk/1/</a> I'm kind of a n00b with Javascript, hope this question isn't stupid. Thank you for taking the time to read it. <a href="http://jsfiddle.net/BTXNk/1/" rel="nofollow">http://jsfiddle.net/BTXNk/1/</a></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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