I am trying to {display:none} on class="filter-form__group" only if ALL child Input’s are ‘disabled’.
<div class="filter-form__group">
<div class="filter-form__group-filter-wrapper" data-filter-type="list">
<div class="filter-form__list-wrapper">
<ul class="filter-form__list">
<li class="filter-item">
<label data-filter-item="" class="filter-item__content">
<input type="checkbox" value="Luggage" disabled>
</label>
</li>
<li class="filter-item">
<label data-filter-item="" class="filter-item__content">
<input type="checkbox" value="Motorcycle" disabled>
</label>
</li>
</ul>
</div>
</div>
</div>
Thanks!
I tried some CSS but they do not seem to work and I believe this may have to be done in JS.
3
Answers
Yep, you’re right—this is something that CSS can’t do. Since you need to check if all the input elements inside a specific group are disabled, JavaScript will work.
Here’s how I would do it:
});
Try this, mostly will work
JSfiddle: https://jsfiddle.net/2e34tzjq/
Iterate over the potentially disabled elements and push truthy comparisons into an empty array. Then compare the length of the array and input elements nodeList length and add/remove a helper class to the target element accordingly.