Hi I'm using jQuery to filter a list of elements that are on a page using a HTML select which has a list of client IDS. The HTML elements on the page have a data attribute of data-client. I'm using jquery to filter out the ones that do not match. However the code I have is hiding all elements. My code is below;
<select class="form-control placeholder" id="filterSelect" name="clients">
<option value="14">Client 14</option>
<option value="45">Client 45</option>
<option value="48">Client 48</option>
</select>
<div class="filterable">
<div class="filter" data-client="14">
<h3>Hello World</h3>
<h4>Client 14</h4>
</div>
<div class="filter" data-client="45">
<h3>Hello World</h3>
<h4>Client 45</h4>
</div>
<div class="filter" data-client="48">
<h3>Hello World</h3>
<h4>Client 48</h4>
</div>
<div class="filter" data-client="14">
<h3>Hello World</h3>
<h4>Client 14</h4>
</div>
<div class="filter" data-client="48">
<h3>Hello World</h3>
<h4>Client 48</h4>
</div>
</div>
My jquery is as follows;
$('#filterSelect').change(function() {
var optionSelected = $("option:selected", this).val();
var filter = $('.filter');
if (filter.attr('data-client') != optionSelected) {
filter.hide();
}
});
I also have a jsfiddle;
https://jsfiddle.net/to53jbe5/
Hope someone can help me filter out the ones that do not match the selected value of the select.