$(buttons).each((index, element) => {
$(element).on('click', event => {
$(element).addClass('active');
// именно такой порядок нужен
$(buttons).not(element).removeClass('active');
})
})
dropdown(event) {
event.preventDefault();
let target = event.currentTarget;
this.dropdownCloseOther(target.parentNode);
let dropdown = target.parentNode.querySelector('.custom-select-dropdown');
dropdown.classList.toggle('active');
}
dropdownCloseOther(not) {
let isActive = false;
if( not.querySelector('.custom-select-dropdown').classList.contains('active') ) isActive = true;
let dropdowns = document.querySelectorAll('.custom-select-dropdown.active');
dropdowns.forEach(dropdown => {
dropdown.classList.remove('active');
})
if( isActive ) not.querySelector('.custom-select-dropdown').classList.add('active');
}
if (!('addEventListener' in NodeList)) {
NodeList.prototype.addEventListener = function (...args) {
for (const node of this.values()) {
node.addEventListener(...args);
}
}
}
if (!('removeEventListener' in NodeList)) {
NodeList.prototype.removeEventListener = function (...args) {
for (const node of this.values()) {
node.removeEventListener(...args);
}
}
}
const elements = document.querySelectorAll('some_selector');
elements.addEventListener('event_type', ...);