The following code is working exactly as expected but I am sure it can be written in a more efficient way.
HTML structure:
<nav class="categories">
<span class="categories__link" id="accesories">Accesories</span>
<span class="categories__link" id="bottoms">Bottoms</span>
<span class="categories__link" id="dresses">Dresses + Jumpsuits</span>
<span class="categories__link" id="outwear">Outerwear</span>
<span class="categories__link" id="top">Tops</span>
<span class="categories__link" id="sale">— Sale</span>
</nav>
<div class="products all-items"> </div>
<div class="products accesories"></div>
<div class="products bottoms"></div>
<div class="products dresses"></div>
<div class="products outwear"></div>
<div class="products tops"></div>
<div class="products sale"></div>
CSS:
.accesories, .bottoms, .dresses, .outwear, .tops, .sale {
display: none;
}
.display-flex {
display: flex;
}
JS:
//Show clothing items sections
function showingSection(e) {
$(e).fadeIn('slow');
$(e).css('display', 'flex');
};
$('#accesories').click(function(){
$('.all-items, .bottoms, .dresses, .outwear, .tops, .sale').css('display', 'none');
showingSection('.accesories');
});
$('#bottoms').click(function(){
$('.all-items, .accesories, .dresses, .outwear, .tops, .sale').css('display', 'none');
showingSection('.bottoms');
});
$('#dresses').click(function(){
$('.all-items, .bottoms, .accesories, .outwear, .tops, .sale').css('display', 'none');
showingSection('.dresses');
});
$('#outwear').click(function(){
$('.all-items, .bottoms, .dresses, .accesories, .tops, .sale').css('display', 'none');
showingSection('.outwear');
});
$('#top').click(function(){
$('.all-items, .bottoms, .dresses, .outwear, .accesories, .sale').css('display', 'none');
showingSection('.tops');
});
$('#sale').click(function(){
$('.all-items, .bottoms, .dresses, .outwear, .tops, .accesories').css('display', 'none');
showingSection('.sale');
});