There is a dropdown in which the user selects a specific position (in this case, the ID is selected). There are also containers that have a data-filter attribute, which, depending on the category, also have an id. We have a dropdown:
<select class="filter"> <option value=1>Name 1</option> <option value=2>Name 2</option> <option value=3>Name 3</option> </select> One of the containers that need to be filtered by the data-filter attribute:
<div class="item" data-filter=2>container</div> There are many such containers. I tried to use the .item selector to run through the each () loop and set the condition in which the containers will be .hide () or .show (). This turned out to be expensive in terms of performance. Then I turned to the filter () function.
var valuee = $(this).val(); // тут извлекаем значение дропдауна,который выбрал пользователь $('.item').filter(function(index){ return $( this ).data( "filter" ) === valuee; }); Does not work. Apparently the problem is in the filter () method, but I don’t catch up with exactly what. How can I rewrite this function to make it work?
$().filter- does not hide / show DOM elements, but returns a wrapper object around a selection of elements.$('.item').filter(...).hide();- Igor