I'm currently working on developing a filter system.
The goal is that when a user clicks on a button, the ID of that specific button will be captured and then display:none;
will be applied to all elements that do not have a matching data
attribute provided.
This is an example of the HTML structure:
<div class="job-list">
<div class="row">
<div class="grid half">
<div class="job-item" data-job-type="fulltime">
<h3>Marketing & Communications Manager</h3>
<h4>Central London - salary competitive</h4>
</div>
</div>
<div class="grid half">
<div class="job-item" data-job-type="parttime">
<h3>Senior PR & Media Manager</h3>
<h4>Central London - salary dependent on experience</h4>
</div>
</div>
</div>
After the user clicks on a button, the variable selection
is designated as either parttime
or fulltime
var selection = 'fulltime';
The objective is to target elements on the page that meet the following criteria:
a) located within .job-list
b) possessing
data-job-type="[the selection var set above]"
$('.job-list div[data-job-type!="'+selection+'"]').css('display','none');
However, the issue arises where it selects the entire .job-list
and applies display:none;
to that section instead of targeting the specific sub-elements that match.