const filterSelector = '.js-filter';
const itemSelector = '.dfth__item';
const checkboxSelector = '.dfth__check:checked';
const labelSelector = '.dfth__label';
const resetSelector = '.dfth__reset';
const selectedSelector = '.js-type-result';
const defaultValue = 'ничего не выбрано';
Вот jquery:
const $filter = $(filterSelector).change(function() {
const selected = $(checkboxSelector, this)
.closest(itemSelector)
.find(labelSelector)
.get()
.map(n => $(n).text())
.join(', ');
$(selectedSelector, this).text(selected || defaultValue);
});
$filter.find(resetSelector).click(() => {
$filter.find(checkboxSelector).prop('checked', false);
$filter.trigger('change');
});
А вот jquery нет:
const filter = document.querySelector(filterSelector);
filter.addEventListener('change', ({ currentTarget: ct }) => {
const selected = Array
.from(
ct.querySelectorAll(checkboxSelector),
n => n.closest(itemSelector).querySelector(labelSelector).textContent)
.join(', ');
ct.querySelector(selectedSelector).textContent = selected || defaultValue;
});
filter.querySelector(resetSelector).addEventListener('click', () => {
filter.querySelectorAll(checkboxSelector).forEach(n => n.checked = false);
filter.dispatchEvent(new Event('change'));
});