There's two problems here, one that you're overwriting your function, so you think you have three when you only have one, but also that you're not filtering by all the filters at once.
What you want here is not three copy-pasted functions, but instead one function that applies all three filters each time something changes.
I also changed it to use regular expressions instead of .find(), which is what allows them to be chained together and allows for a natural behavior of 'all' instead of using a bunch of if statements.
// If any of the filters change
$('select').change(function() {
runAllFilters();
});
function runAllFilters() {
var list = $(".news-list .news-item");
$(list).fadeOut("fast");
var filtered = $(".news-list article");
// Get all filter values
var cost = $('select#sort-cost').val();
var city = $('select#sort-city').val();
var age = $('select#sort-age').val();
// Filter based on all of them
filtered = filtered.filter(function() {
return RegExp(cost).test($(this).attr("data-category")) &&
RegExp(age).test($(this).attr("data-age")) &&
RegExp(city).test($(this).attr("data-city"));
});
// Show message if there are no results
filtered.length === 0
? $('.news-list').append("<p id='noresults'>No Results!</p>")
: $('#noresults').remove()
// Display Them
filtered.each(function (i) {
$(this).delay(100).slideDown("fast");
});
};
This approach also takes a lot of the repetition out of the code.
The only thing I changed in the HTML is to change the value 'All' to just '.' so that you don't need a bunch of if statements; in RegEx "." matches everything so it works as-is.
<select name="sort-cost" id="sort-cost">
<option value=".">All</option>
<option value="1">Bestsellers</option>
<option value="2">Sales</option>
</select>
// If any of the filters change
$('select').change(function() {
runAllFilters();
});
function runAllFilters() {
var list = $(".news-list .news-item");
$(list).fadeOut("fast");
var filtered = $(".news-list article");
// Get all filter values
var cost = $('select#sort-cost').val();
var city = $('select#sort-city').val();
var age = $('select#sort-age').val();
// Filter based on all of them
filtered = filtered.filter(function() {
return RegExp(cost).test($(this).attr("data-category")) &&
RegExp(age).test($(this).attr("data-age")) &&
RegExp(city).test($(this).attr("data-city"));
});
filtered.length === 0
? $('.news-list').append("<p id='noresults'>No Results!</p>")
: $('#noresults').remove()
// Display Them
filtered.each(function (i) {
$(this).delay(100).slideDown("fast");
});
};
.news-item{
display:inline-block;
vertical-align:top;
width:20%;
text-align:center;
background: #fff;
border:1px solid #333;
float:left;
}
.sort{
display:inline-block;
margin-right:30px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1>SORT NOW</h1>
<div class="sort">
COST
<select name="sort-cost" id="sort-cost">
<option value=".">All</option>
<option value="1">Bestsellers</option>
<option value="2">Sales</option>
</select>
</div>
<div class="sort">
AGE
<select name="sort-age" id="sort-age">
<option value=".">All</option>
<option value="a">3+</option>
<option value="b">5+</option>
<option value="c">9+</option>
</select>
</div>
<div class="sort">
CITY
<select name="sort-city" id="sort-city">
<option value=".">All</option>
<option value="ny">New York</option>
<option value="la">Los Angeles</option>
<option value="lv">Las Vegas</option>
</select>
</div>
<br><br>
<section class="news-list">
<article class="news-item" data-category="1 2" data-age="a" data-city="la lv ny">
<div class="thumb">
<img src="http://placehold.it/100x100">
</div>
<div class="news-txt">
<p>First one</p>
</div>
</article>
<article class="news-item" data-category="1" data-age="a b" data-city="ny">
<div class="thumb">
<img src="http://placehold.it/100x100">
</div>
<div class="news-txt">
<p>Second one</p>
</div>
</article>
<article class="news-item" data-category="2" data-age="a b" data-city="la ny">
<div class="thumb">
<img src="http://placehold.it/100x100">
</div>
<div class="news-txt">
<p>Third one</p>
</div>
</article>
<article class="news-item" data-category="1 2" data-age="c" data-city="la lv ny">
<div class="thumb">
<img src="http://placehold.it/100x100">
</div>
<div class="news-txt">
<p>Fifth</p>
</div>
</article>
</section>
filterList, and told it to do X. You then define another function, also calling itfilterList, this time telling it to do Y. You can not have two functions called the same thing, so your firstfilterListis overwritten