$('.search').on('input', function() {
const search = $(this).val().trim().toLowerCase();
$('.metro-line__item')
.hide()
.filter((i, n) => $('.metro__name', n).text().toLowerCase().includes(search))
.show();
$('.metro-line')
.show()
.not(':has(.metro-line__item:visible)')
.hide();
});
или
.hidden {
display: none;
}
document.querySelector('.search').addEventListener('input', e => {
const search = e.target.value.trim().toLowerCase();
document.querySelectorAll('.metro-line__item').forEach(n => {
const name = n.querySelector('.metro__name').textContent.toLowerCase();
n.classList.toggle('hidden', !name.includes(search));
});
document.querySelectorAll('.metro-line').forEach(n => {
n.classList.toggle('hidden', !n.querySelector('.metro-line__item:not(.hidden)'));
});
});