Depending on the state of the checkbox, I am trying to show/hide each .item
if its nested element .nested
has the invisible class. So either on change or on load I want the code to recognize the state of the checkbox and show / hide the .item
if it's nested element has the invisible class.
$(function() {
hideArchive();
$("#toggle").change(hideArchive);
});
function hideArchive() {
$(".item").each(function() {
var $this = $(this);
if ($(".nested", this).hasClass("w-condition-invisible")) {
$this.hide();
} else {
$this.show();
}
});
}
.item {
border: 1px solid;
padding: 24px
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="toggle" checked>
<div class="item">
<div class="nested"></div>
</div>
<div class="item">
<div class="nested w-condition-invisible"></div>
</div>
<div class="item">
<div class="nested"></div>
</div>