@property
const liked = new Set();
// ловить вообще все клики
document.addEventListener('click', e => {
const el = e.target;
if (!el.classList.contains('click')) return; // неинтересный клик
if (liked.has(el)) { // уже выбран этот?
liked.delete(el); // удалить
} else {
liked.add(el); // добавить
}
// пора показать что-нибудь
document.querySelector('span.text').innerText = liked.size; // счётчик
// список выбранных
document.querySelector('span.list').innerText = [...liked.values()]
.map(({innerText: t}) => t)
.join(', ');
});
let count = 0;
const countEl = document.querySelector('.text');
const buttons = [...document.querySelectorAll('.click')];
const onClick = e => updateCount(e.target.classList.toggle('clicked') ? 1 : -1);
const updateCount = change => countEl.innerText = count += change;
buttons.forEach(n => n.addEventListener('click', onClick));
updateCount(buttons.reduce((acc, n) => acc + n.classList.contains('clicked'), 0));
$(document).on('click', '.list li.active', function(){
$('.button').addClass('blue')
})
stepsSlider.noUiSlider.on('change.one', function() {
vals = stepsSlider.noUiSlider.get();
var processed = vals.replace(/ /g, '');
res = parseFloat(processed, 10);
// Как то так https://refreshless.com/nouislider/more/#section-update
stepsSlider2.noUiSlider.updateOptions({
range: {
'min': 0,
'max': res
}
});
});
.on('beforeChange', function(e, slick, currSlide, nextSlide) {
$('.tabs-content__item').hide().eq(nextSlide).fadeIn();
});
- .dropdown__block.open {
+ .dropdown.open .dropdown__block {
const containerSelector = '.dropdown';
const buttonSelector = `${containerSelector} .dropdown__toggler`;
const activeClass = 'open';
// jquery, как вы и хотели
$(document).on('click', ({ target: t }) => {
const $container = $(t).closest(containerSelector);
const $button = $(t).closest(buttonSelector);
if ($button.length) {
$container.toggleClass(activeClass);
}
$(containerSelector).not($container).removeClass(activeClass);
});
// или, к чёрту jquery
document.addEventListener('click', ({ target: t }) => {
const container = t.closest(containerSelector);
const button = t.closest(buttonSelector);
if (button) {
container.classList.toggle(activeClass);
}
document.querySelectorAll(containerSelector).forEach(n => {
if (n !== container) {
n.classList.remove(activeClass);
}
});
});
$('.block').click(function(e){
var $this = $(this);
var $target = $(e.target);
if($this.is($target)) {
$('.hidden').slideToggle();
}
});
$('.block').click(function(e){
var $target = $(e.target);
if(!$target.attr('href')) {
$('.hidden').slideToggle();
}
});
.slick-dots {
li button {
background-color: red;
}
li.slick-active ~ li button {
background-color: blue;
}
}
const containerSelector = 'ul';
const itemSelector = 'li';
const activeClass = 'active';
const $containers = $(containerSelector).on('click', itemSelector, function(e) {
const index = $(itemSelector, e.delegateTarget).index(this);
$containers.find(`${itemSelector}.${activeClass}`).removeClass(activeClass);
$containers.find(`${itemSelector}:eq(${index})`).addClass(activeClass);
});
const containers = document.querySelectorAll(containerSelector);
containers.forEach(n => n.addEventListener('click', onClick));
function onClick(e) {
const item = e.target.closest(itemSelector);
if (item) {
const items = this.querySelectorAll(itemSelector);
const index = Array.prototype.indexOf.call(items, item);
containers.forEach(container => {
container.querySelectorAll(itemSelector).forEach((n, i) => {
n.classList.toggle(activeClass, i === index);
})
});
}
}