There is a simple filter

$('.trainers__nav a').on('click', function(e) { e.preventDefault(); var elems = $('.trainers__item[data-type="' + $(this).attr('value') + '"]'); elems.addClass('trainers__item_show'); $('.trainers__item').not(elems).addClass('trainers__item_disable').removeClass('trainers__item_show'); if ($(this).attr('value') == 'all') { $('.trainers__item').removeClass('trainers__item_disable'); }; }); 

How to check data attribute of an article if it can have several categories? Example:

 <article class="trainers__item" data-type="old student"> <span>old student</span> </article> 

fiddle

thank

    1 answer 1

    The answer was very simple:

    Instead of equality in the search string, it was necessary to check that the value of the attribute contains it, that is:

    Instead of [data-type=" you need [data-type*="

    • I hope your answer is correct)))) - Lyuba Ivanova
    • @LyubaIvanova for my specific task, it is correct) - Atomrr