Consider the following:
jQuery('document').ready(function($) {
$('#num-locations input[type="checkbox"]').on('click', function(e) {
if (e.target.checked) {
dataId = e.target.dataset.location;
console.log(dataId);
$('.jobs-listing [data-city]').not('[data-city*="'+dataId+'"]').hide();
} else {
$('.jobs-listing [data-city]').show();
}
});
});
Here's an example of the HTML, there could be tons of these:
<div class="manage-wrapper d-flex py-5 eachJob" data-city="Ottawa" data-province="Ontario">
<div class="manage-text w-7">
<h4 class="font-weight-bold mt-0 mb-1 job-title"></h4>
<p class="job-description"></p>
</div>
<div class="manage-aside text-right w-3">
<h4 class="font-weight-bold mt-0 mb-1 job-location">Ottawa</h4>
<p class="mb-0 job-province">Ontario</p>
<a href="#" class="btn btn-primary job-url" tabindex="-1">VIEW JOB</a>
</div>
</div>
Expected: Apply display none, only to the parent div, in this case
'.manage-wrapper'Actual: Everything on the page is hidden, because a "display: none" is applied to every dive inside the
.manage-wrapperbut not applied to the.manage-wrapperit's self.There are no console errors when you click said checkbox.
Whats the proper way to apply: display: none to any div with a class manage-wrapper upon click when the data-location does not match the data-city?
[And]
When You uncheck said checkbox, whats the proper way to restore the "hidden" elements?